1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

WL#4444 Added TRUNCATE partition support, fixes bug#19405 and bug #35111

This commit is contained in:
Mikael Ronstrom
2009-09-10 11:15:39 +02:00
parent 51c27a6942
commit ff1df12a20
32 changed files with 1810 additions and 11 deletions

View File

@ -1062,7 +1062,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
it should only do named partitions, otherwise all partitions
*/
if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) ||
part_elem->part_state == PART_CHANGED)
part_elem->part_state == PART_ADMIN)
{
if (m_is_sub_partitioned)
{
@ -1123,6 +1123,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
DBUG_RETURN(error);
}
}
part_elem->part_state= PART_NORMAL;
}
} while (++i < no_parts);
DBUG_RETURN(FALSE);
@ -3202,6 +3203,9 @@ int ha_partition::delete_row(const uchar *buf)
Called from sql_delete.cc by mysql_delete().
Called from sql_select.cc by JOIN::reinit().
Called from sql_union.cc by st_select_lex_unit::exec().
Also used for handle ALTER TABLE t TRUNCATE PARTITION ...
NOTE: auto increment value will be truncated in that partition as well!
*/
int ha_partition::delete_all_rows()
@ -3214,11 +3218,84 @@ int ha_partition::delete_all_rows()
if (thd->lex->sql_command == SQLCOM_TRUNCATE)
{
Alter_info *alter_info= &thd->lex->alter_info;
HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
/* TRUNCATE also means resetting auto_increment */
lock_auto_increment();
ha_data->next_auto_inc_val= 0;
ha_data->auto_inc_initialized= FALSE;
unlock_auto_increment();
if (alter_info->flags & ALTER_ADMIN_PARTITION)
{
/* ALTER TABLE t TRUNCATE PARTITION ... */
List_iterator<partition_element> part_it(m_part_info->partitions);
int saved_error= 0;
uint no_parts= m_part_info->no_parts;
uint no_subparts= m_part_info->no_subparts;
uint i= 0;
uint no_parts_set= alter_info->partition_names.elements;
uint no_parts_found= set_part_state(alter_info, m_part_info,
PART_ADMIN);
if (no_parts_set != no_parts_found &&
(!(alter_info->flags & ALTER_ALL_PARTITION)))
DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
/*
Cannot return HA_ERR_WRONG_COMMAND here without correct pruning
since that whould delete the whole table row by row in sql_delete.cc
*/
bitmap_clear_all(&m_part_info->used_partitions);
do
{
partition_element *part_elem= part_it++;
if (part_elem->part_state == PART_ADMIN)
{
if (m_is_sub_partitioned)
{
List_iterator<partition_element>
subpart_it(part_elem->subpartitions);
partition_element *sub_elem;
uint j= 0, part;
do
{
sub_elem= subpart_it++;
part= i * no_subparts + j;
bitmap_set_bit(&m_part_info->used_partitions, part);
if (!saved_error)
{
DBUG_PRINT("info", ("truncate subpartition %u (%s)",
part, sub_elem->partition_name));
if ((error= m_file[part]->ha_delete_all_rows()))
saved_error= error;
/* If not reset_auto_increment is supported, just accept it */
if (!saved_error &&
(error= m_file[part]->ha_reset_auto_increment(0)) &&
error != HA_ERR_WRONG_COMMAND)
saved_error= error;
}
} while (++j < no_subparts);
}
else
{
DBUG_PRINT("info", ("truncate partition %u (%s)", i,
part_elem->partition_name));
bitmap_set_bit(&m_part_info->used_partitions, i);
if (!saved_error)
{
if ((error= m_file[i]->ha_delete_all_rows()) && !saved_error)
saved_error= error;
/* If not reset_auto_increment is supported, just accept it */
if (!saved_error &&
(error= m_file[i]->ha_reset_auto_increment(0)) &&
error != HA_ERR_WRONG_COMMAND)
saved_error= error;
}
}
part_elem->part_state= PART_NORMAL;
}
} while (++i < no_parts);
DBUG_RETURN(saved_error);
}
truncate= TRUE;
}
file= m_file;
@ -5842,12 +5919,14 @@ enum row_type ha_partition::get_row_type() const
void ha_partition::print_error(int error, myf errflag)
{
THD *thd= ha_thd();
DBUG_ENTER("ha_partition::print_error");
/* Should probably look for my own errors first */
DBUG_PRINT("enter", ("error: %d", error));
if (error == HA_ERR_NO_PARTITION_FOUND)
if (error == HA_ERR_NO_PARTITION_FOUND &&
thd->lex->sql_command != SQLCOM_TRUNCATE)
m_part_info->print_no_partition_found(table);
else
m_file[m_last_part]->print_error(error, errflag);