Skip to content
Permalink
Browse files
Move alter partition flags to alter_info->partition_flags
This is done to get more free flag bits for alter_info->flags

Renamed all ALTER PARTITION defines to start with ALTER_PARTITION_
Renamed ALTER_PARTITION to ALTER_PARTITION_INFO
Renamed ALTER_TABLE_REORG to ALTER_PARTITION_TABLE_REORG

Other things:
- Shifted some ALTER_xxx defines to get empty bits at end
  • Loading branch information
montywi committed Mar 29, 2018
1 parent 2dbeebd commit ab19412
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 164 deletions.
@@ -1380,7 +1380,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
when ALTER TABLE <CMD> PARTITION ...
it should only do named partitions, otherwise all partitions
*/
if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) ||
if (!(thd->lex->alter_info.partition_flags & ALTER_PARTITION_ADMIN) ||
part_elem->part_state == PART_ADMIN)
{
if (m_is_sub_partitioned)
@@ -9655,7 +9655,7 @@ void ha_partition::print_error(int error, myf errflag)

/* Should probably look for my own errors first */
if ((error == HA_ERR_NO_PARTITION_FOUND) &&
! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION))
! (thd->lex->alter_info.partition_flags & ALTER_PARTITION_TRUNCATE))
{
m_part_info->print_no_partition_found(table, errflag);
DBUG_VOID_RETURN;
@@ -9871,8 +9871,11 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table,
Any other change would set partition_changed in
prep_alter_part_table() in mysql_alter_table().
*/
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
if (ha_alter_info->alter_info->partition_flags == ALTER_PARTITION_INFO)
{
DBUG_ASSERT(ha_alter_info->alter_info->flags == 0);
DBUG_RETURN(HA_ALTER_INPLACE_NO_LOCK);
}

part_inplace_ctx=
new (thd->mem_root) ha_partition_inplace_ctx(thd, m_tot_parts);
@@ -9938,8 +9941,11 @@ bool ha_partition::prepare_inplace_alter_table(TABLE *altered_table,
Changing to similar partitioning, only update metadata.
Non allowed changes would be catched in prep_alter_part_table().
*/
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
if (ha_alter_info->alter_info->partition_flags == ALTER_PARTITION_INFO)
{
DBUG_ASSERT(ha_alter_info->alter_info->flags == 0);
DBUG_RETURN(false);
}

part_inplace_ctx=
static_cast<class ha_partition_inplace_ctx*>(ha_alter_info->handler_ctx);
@@ -9971,8 +9977,11 @@ bool ha_partition::inplace_alter_table(TABLE *altered_table,
Changing to similar partitioning, only update metadata.
Non allowed changes would be catched in prep_alter_part_table().
*/
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
if (ha_alter_info->alter_info->partition_flags == ALTER_PARTITION_INFO)
{
DBUG_ASSERT(ha_alter_info->alter_info->flags == 0);
DBUG_RETURN(false);
}

part_inplace_ctx=
static_cast<class ha_partition_inplace_ctx*>(ha_alter_info->handler_ctx);
@@ -10011,8 +10020,11 @@ bool ha_partition::commit_inplace_alter_table(TABLE *altered_table,
Changing to similar partitioning, only update metadata.
Non allowed changes would be catched in prep_alter_part_table().
*/
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
if (ha_alter_info->alter_info->partition_flags == ALTER_PARTITION_INFO)
{
DBUG_ASSERT(ha_alter_info->alter_info->flags == 0);
DBUG_RETURN(false);
}

part_inplace_ctx=
static_cast<class ha_partition_inplace_ctx*>(ha_alter_info->handler_ctx);
@@ -597,35 +597,10 @@ typedef ulonglong alter_table_operations;
#define ALTER_KEYS_ONOFF (1ULL << 9)
// Set for FORCE, ENGINE(same engine), by mysql_recreate_table()
#define ALTER_RECREATE (1ULL << 10)
// Set for ADD PARTITION
#define ALTER_ADD_PARTITION (1ULL << 11)
// Set for DROP PARTITION
#define ALTER_DROP_PARTITION (1ULL << 12)
// Set for COALESCE PARTITION
#define ALTER_COALESCE_PARTITION (1ULL << 13)
// Set for REORGANIZE PARTITION ... INTO
#define ALTER_REORGANIZE_PARTITION (1ULL << 14)
// Set for partition_options
#define ALTER_PARTITION (1ULL << 15)
// Set for LOAD INDEX INTO CACHE ... PARTITION
// Set for CACHE INDEX ... PARTITION
#define ALTER_ADMIN_PARTITION (1ULL << 16)
// Set for REORGANIZE PARTITION
#define ALTER_TABLE_REORG (1ULL << 17)
// Set for REBUILD PARTITION
#define ALTER_REBUILD_PARTITION (1ULL << 18)
// Set for partitioning operations specifying ALL keyword
#define ALTER_ALL_PARTITION (1ULL << 19)
// Set for REMOVE PARTITIONING
#define ALTER_REMOVE_PARTITIONING (1ULL << 20)
// Set for ADD FOREIGN KEY
#define ALTER_ADD_FOREIGN_KEY (1ULL << 21)
// Set for DROP FOREIGN KEY
#define ALTER_DROP_FOREIGN_KEY (1ULL << 22)
// Set for EXCHANGE PARITION
#define ALTER_EXCHANGE_PARTITION (1ULL << 23)
// Set by Sql_cmd_alter_table_truncate_partition::execute()
#define ALTER_TRUNCATE_PARTITION (1ULL << 24)
// Set for ADD [COLUMN] FIRST | AFTER
#define ALTER_COLUMN_ORDER (1ULL << 25)
#define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27)
@@ -713,30 +688,60 @@ typedef ulonglong alter_table_operations;
#define ALTER_COLUMN_NOT_NULLABLE (1ULL << 54)

// Change column generation expression
#define ALTER_VIRTUAL_GCOL_EXPR (1ULL << 56)
#define ALTER_STORED_GCOL_EXPR (1ULL << 57)
#define ALTER_VIRTUAL_GCOL_EXPR (1ULL << 55)
#define ALTER_STORED_GCOL_EXPR (1ULL << 56)

// column's engine options changed, something in field->option_struct
#define ALTER_COLUMN_OPTION (1ULL << 59)
#define ALTER_COLUMN_OPTION (1ULL << 57)

// MySQL alias for the same thing:
#define ALTER_COLUMN_STORAGE_TYPE (1ULL << 60)
#define ALTER_COLUMN_STORAGE_TYPE (1ULL << 58)

// Change the column format of column
#define ALTER_COLUMN_COLUMN_FORMAT (1ULL << 61)
#define ALTER_COLUMN_COLUMN_FORMAT (1ULL << 59)

/**
Changes in generated columns that affect storage,
for example, when a vcol type or expression changes
and this vcol is indexed or used in a partitioning expression
*/
#define ALTER_COLUMN_VCOL (1ULL << 62)
#define ALTER_COLUMN_VCOL (1ULL << 60)

/**
ALTER TABLE for a partitioned table. The engine needs to commit
online alter of all partitions atomically (using group_commit_ctx)
*/
#define ALTER_PARTITIONED (1ULL << 63)
#define ALTER_PARTITIONED (1ULL << 61)

/*
Flags set in partition_flags when altering partitions
*/

// Set for ADD PARTITION
#define ALTER_PARTITION_ADD (1ULL << 1)
// Set for DROP PARTITION
#define ALTER_PARTITION_DROP (1ULL << 2)
// Set for COALESCE PARTITION
#define ALTER_PARTITION_COALESCE (1ULL << 3)
// Set for REORGANIZE PARTITION ... INTO
#define ALTER_PARTITION_REORGANIZE (1ULL << 4)
// Set for partition_options
#define ALTER_PARTITION_INFO (1ULL << 5)
// Set for LOAD INDEX INTO CACHE ... PARTITION
// Set for CACHE INDEX ... PARTITION
#define ALTER_PARTITION_ADMIN (1ULL << 6)
// Set for REBUILD PARTITION
#define ALTER_PARTITION_REBUILD (1ULL << 7)
// Set for partitioning operations specifying ALL keyword
#define ALTER_PARTITION_ALL (1ULL << 8)
// Set for REMOVE PARTITIONING
#define ALTER_PARTITION_REMOVE (1ULL << 9)
// Set for EXCHANGE PARITION
#define ALTER_PARTITION_EXCHANGE (1ULL << 10)
// Set by Sql_cmd_alter_table_truncate_partition::execute()
#define ALTER_PARTITION_TRUNCATE (1ULL << 11)
// Set for REORGANIZE PARTITION
#define ALTER_PARTITION_TABLE_REORG (1ULL << 12)

/*
This is master database for most of system tables. However there
@@ -2285,6 +2290,9 @@ class Alter_inplace_info
*/
alter_table_operations handler_flags;

/* Alter operations involving parititons are strored here */
ulong partition_flags;

/**
Partition_info taking into account the partition changes to be performed.
Contains all partitions which are present in the old version of the table
@@ -2442,7 +2442,7 @@ static bool strcmp_null(const char *a, const char *b)
such partitioned tables using numeric colums in the partitioning expression.
For more info see bug#14521864.
Does not check if columns etc has changed, i.e. only for
alter_info->flags == ALTER_PARTITION.
alter_info->partition_flags == ALTER_PARTITION_INFO.
*/

bool partition_info::has_same_partitioning(partition_info *new_part_info)
@@ -339,7 +339,7 @@ static bool open_only_one_table(THD* thd, TABLE_LIST* table,
to differentiate from ALTER TABLE...CHECK PARTITION on which view is not
allowed.
*/
if (lex->alter_info.flags & ALTER_ADMIN_PARTITION ||
if (lex->alter_info.partition_flags & ALTER_PARTITION_ADMIN ||
!is_view_operator_func)
{
table->required_type= TABLE_TYPE_NORMAL;
@@ -562,7 +562,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
*/
Alter_info *alter_info= &lex->alter_info;

if (alter_info->flags & ALTER_ADMIN_PARTITION)
if (alter_info->partition_flags & ALTER_PARTITION_ADMIN)
{
if (!table->table->part_info)
{
@@ -1002,7 +1002,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
Alter_info *alter_info= &lex->alter_info;

protocol->store(STRING_WITH_LEN("note"), system_charset_info);
if (alter_info->flags & ALTER_ADMIN_PARTITION)
if (alter_info->partition_flags & ALTER_PARTITION_ADMIN)
{
protocol->store(STRING_WITH_LEN(
"Table does not support optimize on partitions. All partitions "
@@ -1046,10 +1046,10 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
save_flags= alter_info->flags;

/*
Reset the ALTER_ADMIN_PARTITION bit in alter_info->flags
Reset the ALTER_PARTITION_ADMIN bit in alter_info->flags
to force analyze on all partitions.
*/
alter_info->flags &= ~(ALTER_ADMIN_PARTITION);
alter_info->partition_flags &= ~(ALTER_PARTITION_ADMIN);
result_code= table->table->file->ha_analyze(thd, check_opt);
if (result_code == HA_ADMIN_ALREADY_DONE)
result_code= HA_ADMIN_OK;
@@ -27,7 +27,7 @@ Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
key_list(rhs.key_list, mem_root),
create_list(rhs.create_list, mem_root),
check_constraint_list(rhs.check_constraint_list, mem_root),
flags(rhs.flags),
flags(rhs.flags), partition_flags(rhs.partition_flags),
keys_onoff(rhs.keys_onoff),
partition_names(rhs.partition_names, mem_root),
num_parts(rhs.num_parts),
@@ -225,13 +225,14 @@ bool Sql_cmd_alter_table::execute(THD *thd)
We also require DROP priv for ALTER TABLE ... DROP PARTITION, as well
as for RENAME TO, as being done by SQLCOM_RENAME_TABLE
*/
if (alter_info.flags & (ALTER_DROP_PARTITION | ALTER_RENAME))
if ((alter_info.partition_flags & ALTER_PARTITION_DROP) ||
(alter_info.flags & ALTER_RENAME))
priv_needed|= DROP_ACL;

/* Must be set in the parser */
DBUG_ASSERT(select_lex->db.str);
DBUG_ASSERT(!(alter_info.flags & ALTER_EXCHANGE_PARTITION));
DBUG_ASSERT(!(alter_info.flags & ALTER_ADMIN_PARTITION));
DBUG_ASSERT(!(alter_info.partition_flags & ALTER_PARTITION_EXCHANGE));
DBUG_ASSERT(!(alter_info.partition_flags & ALTER_PARTITION_ADMIN));
if (check_access(thd, priv_needed, first_table->db.str,
&first_table->grant.privilege,
&first_table->grant.m_internal,
@@ -43,14 +43,14 @@ class Alter_info

bool partition_modifying() const
{
return flags & (
ALTER_DROP_PARTITION |
ALTER_COALESCE_PARTITION |
ALTER_REORGANIZE_PARTITION |
ALTER_REMOVE_PARTITIONING |
ALTER_TABLE_REORG |
ALTER_EXCHANGE_PARTITION |
ALTER_TRUNCATE_PARTITION);
return partition_flags & (
ALTER_PARTITION_DROP |
ALTER_PARTITION_COALESCE |
ALTER_PARTITION_REORGANIZE |
ALTER_PARTITION_REMOVE |
ALTER_PARTITION_TABLE_REORG |
ALTER_PARTITION_EXCHANGE |
ALTER_PARTITION_TRUNCATE);
}

/**
@@ -106,6 +106,7 @@ class Alter_info
List<Virtual_column_info> check_constraint_list;
// Type of ALTER TABLE operation.
alter_table_operations flags;
ulong partition_flags;
// Enable or disable keys.
enum_enable_or_disable keys_onoff;
// List of partitions.
@@ -119,7 +120,7 @@ class Alter_info


Alter_info() :
flags(0),
flags(0), partition_flags(0),
keys_onoff(LEAVE_AS_IS),
num_parts(0),
requested_algorithm(ALTER_TABLE_ALGORITHM_DEFAULT),
@@ -134,6 +135,7 @@ class Alter_info
create_list.empty();
check_constraint_list.empty();
flags= 0;
partition_flags= 0;
keys_onoff= LEAVE_AS_IS;
num_parts= 0;
partition_names.empty();
@@ -5050,8 +5050,8 @@ int st_select_lex_unit::save_union_explain_part2(Explain_query *output)
bool LEX::is_partition_management() const
{
return (sql_command == SQLCOM_ALTER_TABLE &&
(alter_info.flags == ALTER_ADD_PARTITION ||
alter_info.flags == ALTER_REORGANIZE_PARTITION));
(alter_info.partition_flags == ALTER_PARTITION_ADD ||
alter_info.partition_flags == ALTER_PARTITION_REORGANIZE));
}


0 comments on commit ab19412

Please sign in to comment.