Commit 65811a33 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#37453: Dropping/creating index on partitioned table with

InnoDB Plugin locks table

The fast/on-line add/drop index handler calls was not implemented
whithin the partitioning.

This implements it in the partitioning handler.

Since this is only used by the not included InnoDB plugin, there
is no test case. (Have tested it manually with the plugin, and
it does not allow unique indexes not including partitioning
function, or removal of pk, which in innodb generates a new pk,
which is not in the partitioning function.)

NOTE: This introduces a new handler method, and because of that
changes the storage engine api. (One cannot use a handlerton to
see the capabilities of a table's handler if it is partitioned.
So I added a wrapper function in the handler that defaults to
the handlerton function, which the partitioning handler overrides.

sql/ha_partition.cc:
  Bug#37453: Dropping/creating index on partitioned table with
  InnoDB Plugin locks table
  
  Added support for fast/on-line add/drop index.
  Implemented alter_table_flags as bit-or of the partitioned
  hton and the first partitions alter_table_flags.
  
  It is only to forward the calls for the other functions:
  check_if_incompatible_data
  add_index
  prepare_drop_index
  final_drop_index
  
  to all parts handler
sql/ha_partition.h:
  Bug#37453: Dropping/creating index on partitioned table with
  InnoDB Plugin locks table
  
  Added support for fast/on-line add/drop index.
sql/handler.h:
  Bug#37453: Dropping/creating index on partitioned table with
  InnoDB Plugin locks table
  
  Added the function on handler level, defaulting to use
  the handlerton function, but a handler can override it.
  Needed for partitioned tables.
  
  NOTE: Change of storage engine api.
sql/sql_partition.cc:
  Bug#37453: Dropping/creating index on partitioned table with
  InnoDB Plugin locks table
  
  Using the new handler function, instead of the handlerton
  function. This works better with the partitioning handler.
sql/sql_table.cc:
  Bug#37453: Dropping/creating index on partitioned table with
  InnoDB Plugin locks table
  
  Using the new handler function, instead of the handlerton
  function. This works better with the partitioning handler.
  Also using new process info for 'manage keys' (kind of fix
  for bug-37550).
parent 1e26e74c
......@@ -5600,6 +5600,89 @@ bool ha_partition::get_error_message(int error, String *buf)
/****************************************************************************
MODULE handler characteristics
****************************************************************************/
/**
alter_table_flags must be on handler/table level, not on hton level
due to the ha_partition hton does not know what the underlying hton is.
*/
uint ha_partition::alter_table_flags(uint flags)
{
DBUG_ENTER("ha_partition::alter_table_flags");
DBUG_RETURN(ht->alter_table_flags(flags) |
m_file[0]->alter_table_flags(flags));
}
/**
check if copy of data is needed in alter table.
*/
bool ha_partition::check_if_incompatible_data(HA_CREATE_INFO *create_info,
uint table_changes)
{
handler **file;
bool ret;
/*
The check for any partitioning related changes have already been done
in mysql_alter_table (by fix_partition_func), so it is only up to
the underlying handlers.
*/
for (file= m_file; *file; file++)
if ((ret= (*file)->check_if_incompatible_data(create_info,
table_changes)) !=
COMPATIBLE_DATA_YES)
break;
return ret;
}
/**
Support of fast or online add/drop index
*/
int ha_partition::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
{
handler **file;
int ret;
/*
There has already been a check in fix_partition_func in mysql_alter_table
before this call, which checks for unique/primary key violations of the
partitioning function. So no need for extra check here.
*/
for (file= m_file; *file; file++)
if ((ret= (*file)->add_index(table_arg, key_info, num_of_keys)))
break;
return ret;
}
int ha_partition::prepare_drop_index(TABLE *table_arg, uint *key_num,
uint num_of_keys)
{
handler **file;
int ret;
/*
DROP INDEX does not affect partitioning.
*/
for (file= m_file; *file; file++)
if ((ret= (*file)->prepare_drop_index(table_arg, key_num, num_of_keys)))
break;
return ret;
}
int ha_partition::final_drop_index(TABLE *table_arg)
{
handler **file;
int ret= HA_ERR_WRONG_COMMAND;
for (file= m_file; *file; file++)
if ((ret= (*file)->final_drop_index(table_arg)))
break;
return ret;
}
/*
If frm_error() is called then we will use this to to find out what file
extensions exist for the storage engine. This is also used by the default
......
......@@ -210,6 +210,8 @@ class ha_partition :public handler
DBUG_RETURN(0);
}
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
uint table_changes);
private:
int prepare_for_rename();
int copy_partitions(ulonglong *copied, ulonglong *deleted);
......@@ -762,6 +764,11 @@ class ha_partition :public handler
return m_file[0]->index_flags(inx, part, all_parts);
}
/**
wrapper function for handlerton alter_table_flags, since
the ha_partition_hton cannot know all its capabilities
*/
virtual uint alter_table_flags(uint flags);
/*
extensions of table handler files
*/
......@@ -898,13 +905,14 @@ class ha_partition :public handler
-------------------------------------------------------------------------
MODULE on-line ALTER TABLE
-------------------------------------------------------------------------
These methods are in the handler interface but never used (yet)
They are to be used by on-line alter table add/drop index:
These methods are in the handler interface. (used by innodb-plugin)
They are used for on-line/fast alter table add/drop index:
-------------------------------------------------------------------------
virtual ulong index_ddl_flags(KEY *wanted_index) const
virtual int add_index(TABLE *table_arg,KEY *key_info,uint num_of_keys);
virtual int drop_index(TABLE *table_arg,uint *key_num,uint num_of_keys);
*/
virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
uint num_of_keys);
virtual int final_drop_index(TABLE *table_arg);
/*
-------------------------------------------------------------------------
......
......@@ -1724,6 +1724,12 @@ class handler :public Sql_alloc
but we don't have a primary key
*/
virtual void use_hidden_primary_key();
virtual uint alter_table_flags(uint flags)
{
if (ht->alter_table_flags)
return ht->alter_table_flags(flags);
return 0;
}
protected:
/* Service methods for use by storage engines. */
......
......@@ -4219,8 +4219,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
alter_info->no_parts= curr_part_no - new_part_no;
}
}
if (table->s->db_type()->alter_table_flags &&
(!(flags= table->s->db_type()->alter_table_flags(alter_info->flags))))
if (!(flags= table->file->alter_table_flags(alter_info->flags)))
{
my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
DBUG_RETURN(1);
......
......@@ -6449,8 +6449,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
uint *idx_p;
uint *idx_end_p;
if (table->s->db_type()->alter_table_flags)
alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
alter_flags= table->file->alter_table_flags(alter_info->flags);
DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
/* Check dropped indexes. */
for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
......@@ -6720,7 +6719,6 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* Copy the data if necessary. */
thd->count_cuted_fields= CHECK_FIELD_WARN; // calc cuted fields
thd->cuted_fields=0L;
thd_proc_info(thd, "copy to tmp table");
copied=deleted=0;
/*
We do not copy data for MERGE tables. Only the children have data.
......@@ -6731,6 +6729,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* We don't want update TIMESTAMP fields during ALTER TABLE. */
new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
new_table->next_number_field=new_table->found_next_number_field;
thd_proc_info(thd, "copy to tmp table");
error= copy_data_between_tables(table, new_table,
alter_info->create_list, ignore,
order_num, order, &copied, &deleted,
......@@ -6742,6 +6741,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
VOID(pthread_mutex_lock(&LOCK_open));
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
VOID(pthread_mutex_unlock(&LOCK_open));
thd_proc_info(thd, "manage keys");
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
alter_info->keys_onoff);
error= ha_autocommit_or_rollback(thd, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment