diff options
Diffstat (limited to 'sql/sql_truncate.cc')
-rw-r--r-- | sql/sql_truncate.cc | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index 8a70e6f6bdb..249a6e21ffc 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -14,6 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "mariadb.h" #include "debug_sync.h" // DEBUG_SYNC #include "table.h" // TABLE, FOREIGN_KEY_INFO #include "sql_class.h" // THD @@ -26,7 +27,8 @@ #include "sql_truncate.h" #include "wsrep_mysqld.h" #include "sql_show.h" //append_identifier() - +#include "sql_select.h" +#include "sql_delete.h" /** Append a list of field names to a string. @@ -38,15 +40,15 @@ */ static bool fk_info_append_fields(THD *thd, String *str, - List<LEX_STRING> *fields) + List<LEX_CSTRING> *fields) { bool res= FALSE; - LEX_STRING *field; - List_iterator_fast<LEX_STRING> it(*fields); + LEX_CSTRING *field; + List_iterator_fast<LEX_CSTRING> it(*fields); while ((field= it++)) { - res|= append_identifier(thd, str, field->str, field->length); + res|= append_identifier(thd, str, field); res|= str->append(", "); } @@ -78,22 +80,17 @@ static const char *fk_info_str(THD *thd, FOREIGN_KEY_INFO *fk_info) `db`.`tbl`, CONSTRAINT `id` FOREIGN KEY (`fk`) REFERENCES `db`.`tbl` (`fk`) */ - res|= append_identifier(thd, &str, fk_info->foreign_db->str, - fk_info->foreign_db->length); + res|= append_identifier(thd, &str, fk_info->foreign_db); res|= str.append("."); - res|= append_identifier(thd, &str, fk_info->foreign_table->str, - fk_info->foreign_table->length); + res|= append_identifier(thd, &str, fk_info->foreign_table); res|= str.append(", CONSTRAINT "); - res|= append_identifier(thd, &str, fk_info->foreign_id->str, - fk_info->foreign_id->length); + res|= append_identifier(thd, &str, fk_info->foreign_id); res|= str.append(" FOREIGN KEY ("); res|= fk_info_append_fields(thd, &str, &fk_info->foreign_fields); res|= str.append(") REFERENCES "); - res|= append_identifier(thd, &str, fk_info->referenced_db->str, - fk_info->referenced_db->length); + res|= append_identifier(thd, &str, fk_info->referenced_db); res|= str.append("."); - res|= append_identifier(thd, &str, fk_info->referenced_table->str, - fk_info->referenced_table->length); + res|= append_identifier(thd, &str, fk_info->referenced_table); res|= str.append(" ("); res|= fk_info_append_fields(thd, &str, &fk_info->referenced_fields); res|= str.append(')'); @@ -150,18 +147,18 @@ fk_truncate_illegal_if_parent(THD *thd, TABLE *table) /* Loop over the set of foreign keys for which this table is a parent. */ while ((fk_info= it++)) { - DBUG_ASSERT(!my_strcasecmp(system_charset_info, - fk_info->referenced_db->str, - table->s->db.str)); - - DBUG_ASSERT(!my_strcasecmp(system_charset_info, - fk_info->referenced_table->str, - table->s->table_name.str)); - - if (my_strcasecmp(system_charset_info, fk_info->foreign_db->str, - table->s->db.str) || - my_strcasecmp(system_charset_info, fk_info->foreign_table->str, - table->s->table_name.str)) + DBUG_ASSERT(!lex_string_cmp(system_charset_info, + fk_info->referenced_db, + &table->s->db)); + + DBUG_ASSERT(!lex_string_cmp(system_charset_info, + fk_info->referenced_table, + &table->s->table_name)); + + if (lex_string_cmp(system_charset_info, fk_info->foreign_db, + &table->s->db) || + lex_string_cmp(system_charset_info, fk_info->foreign_table, + &table->s->table_name)) break; } @@ -216,7 +213,7 @@ Sql_cmd_truncate_table::handler_truncate(THD *thd, TABLE_LIST *table_ref, or writing into the table. Yet, to open a write cursor we need a thr_lock lock. Allow to open base tables only. */ - table_ref->required_type= FRMTYPE_TABLE; + table_ref->required_type= TABLE_TYPE_NORMAL; /* Ignore pending FLUSH TABLES since we don't want to release the MDL lock taken above and otherwise there is no way to @@ -248,8 +245,8 @@ Sql_cmd_truncate_table::handler_truncate(THD *thd, TABLE_LIST *table_ref, table_ref->table->file->print_error(error, MYF(0)); /* If truncate method is not implemented then we don't binlog the - statement. If truncation has failed in a transactional engine then also we - donot binlog the statment. Only in non transactional engine we binlog + statement. If truncation has failed in a transactional engine then also + we don't binlog the statment. Only in non transactional engine we binlog inspite of errors. */ if (error == HA_ERR_WRONG_COMMAND || @@ -301,8 +298,8 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, */ if (thd->locked_tables_mode) { - if (!(table= find_table_for_mdl_upgrade(thd, table_ref->db, - table_ref->table_name, FALSE))) + if (!(table= find_table_for_mdl_upgrade(thd, table_ref->db.str, + table_ref->table_name.str, FALSE))) DBUG_RETURN(TRUE); *hton_can_recreate= ha_check_storage_engine_flag(table->s->db_type(), @@ -311,17 +308,21 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, } else { + handlerton *hton; + bool is_sequence; + /* Acquire an exclusive lock. */ DBUG_ASSERT(table_ref->next_global == NULL); if (lock_table_names(thd, table_ref, NULL, thd->variables.lock_wait_timeout, 0)) DBUG_RETURN(TRUE); - handlerton *hton; - if (!ha_table_exists(thd, table_ref->db, table_ref->table_name, &hton) || + if (!ha_table_exists(thd, &table_ref->db, &table_ref->table_name, + &hton, &is_sequence) || hton == view_pseudo_hton) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_ref->db, table_ref->table_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), table_ref->db.str, + table_ref->table_name.str); DBUG_RETURN(TRUE); } @@ -337,7 +338,7 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, *hton_can_recreate= false; } else - *hton_can_recreate= hton->flags & HTON_CAN_RECREATE; + *hton_can_recreate= !is_sequence && hton->flags & HTON_CAN_RECREATE; } /* @@ -359,8 +360,8 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, else { /* Table is already locked exclusively. Remove cached instances. */ - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db, - table_ref->table_name, FALSE); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db.str, + table_ref->table_name.str, FALSE); } DBUG_RETURN(FALSE); @@ -413,7 +414,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) bool hton_can_recreate; if (WSREP(thd) && - wsrep_to_isolation_begin(thd, table_ref->db, table_ref->table_name, 0)) + wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, 0)) DBUG_RETURN(TRUE); if (lock_table(thd, table_ref, &hton_can_recreate)) DBUG_RETURN(TRUE); @@ -424,7 +425,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) The storage engine can truncate the table by creating an empty table with the same structure. */ - error= dd_recreate_table(thd, table_ref->db, table_ref->table_name); + error= dd_recreate_table(thd, table_ref->db.str, table_ref->table_name.str); if (thd->locked_tables_mode && thd->locked_tables_list.reopen_tables(thd, false)) thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); @@ -477,7 +478,6 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) DBUG_RETURN(error); } - /** Execute a TRUNCATE statement at runtime. @@ -489,13 +489,13 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) bool Sql_cmd_truncate_table::execute(THD *thd) { bool res= TRUE; - TABLE_LIST *first_table= thd->lex->select_lex.table_list.first; + TABLE_LIST *table= thd->lex->select_lex.table_list.first; DBUG_ENTER("Sql_cmd_truncate_table::execute"); - if (check_one_table_access(thd, DROP_ACL, first_table)) + if (check_one_table_access(thd, DROP_ACL, table)) DBUG_RETURN(res); - if (! (res= truncate_table(thd, first_table))) + if (! (res= truncate_table(thd, table))) my_ok(thd); DBUG_RETURN(res); |