Commit ced213fb authored by unknown's avatar unknown

RB://518 approved by Jimmy Yang and Sunny bains

    
Code cleanup after changes for Bug 56628.  The general approach for 
InnoDB is to make a reference to each enum value whenever it is used in a
switch statement.  In addition, no default case should be used for switch 
statements on enum types.  This assures that if there is ever any change 
in the enum values, the switch will need to change to reflect it since a 
compiler warning will occur.  In this case, the enum row_type is declared 
in handler.h and could be changed for another storage engine.  If so, a 
warning will occur in the InnoDB build.  

Other changes;
* This patch uses 2 macros to help consolidate warning messages that
   need to occur twice in the single switch for row_format.
* Using row_format as the variable name to distinguish it from the enum
  type.
* Function declaration format correction.
parent d499eaec
...@@ -6293,10 +6293,11 @@ create_clustered_index_when_no_primary( ...@@ -6293,10 +6293,11 @@ create_clustered_index_when_no_primary(
/*****************************************************************//** /*****************************************************************//**
Return a display name for the row format Return a display name for the row format
@return row format name */ @return row format name */
UNIV_INTERN
const char *get_row_format_name( const char*
/*============================*/ get_row_format_name(
enum row_type row_format) /*!< in: Row Format */ /*================*/
enum row_type row_format) /*!< in: Row Format */
{ {
switch (row_format) { switch (row_format) {
case ROW_TYPE_COMPACT: case ROW_TYPE_COMPACT:
...@@ -6311,12 +6312,38 @@ enum row_type row_format) /*!< in: Row Format */ ...@@ -6311,12 +6312,38 @@ enum row_type row_format) /*!< in: Row Format */
return("DEFAULT"); return("DEFAULT");
case ROW_TYPE_FIXED: case ROW_TYPE_FIXED:
return("FIXED"); return("FIXED");
default: case ROW_TYPE_PAGE:
case ROW_TYPE_NOT_USED:
break; break;
} }
return("NOT USED"); return("NOT USED");
} }
/** If file-per-table is missing, issue warning and set ret false */
#define CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE \
if (!srv_file_per_table) { \
push_warning_printf( \
thd, MYSQL_ERROR::WARN_LEVEL_WARN, \
ER_ILLEGAL_HA_CREATE_OPTION, \
"InnoDB: ROW_FORMAT=%s requires" \
" innodb_file_per_table.", \
get_row_format_name(row_format)); \
ret = FALSE; \
}
/** If file-format is Antelope, issue warning and set ret false */
#define CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE \
if (srv_file_format < DICT_TF_FORMAT_ZIP) { \
push_warning_printf( \
thd, MYSQL_ERROR::WARN_LEVEL_WARN, \
ER_ILLEGAL_HA_CREATE_OPTION, \
"InnoDB: ROW_FORMAT=%s requires" \
" innodb_file_format > Antelope.", \
get_row_format_name(row_format)); \
ret = FALSE; \
}
/*****************************************************************//** /*****************************************************************//**
Validates the create options. We may build on this function Validates the create options. We may build on this function
in future. For now, it checks two specifiers: in future. For now, it checks two specifiers:
...@@ -6334,7 +6361,7 @@ create_options_are_valid( ...@@ -6334,7 +6361,7 @@ create_options_are_valid(
{ {
ibool kbs_specified = FALSE; ibool kbs_specified = FALSE;
ibool ret = TRUE; ibool ret = TRUE;
enum row_type row_type = form->s->row_type; enum row_type row_format = form->s->row_type;
ut_ad(thd != NULL); ut_ad(thd != NULL);
...@@ -6343,23 +6370,6 @@ create_options_are_valid( ...@@ -6343,23 +6370,6 @@ create_options_are_valid(
return(TRUE); return(TRUE);
} }
/* Check for a valid Innodb ROW_FORMAT specifier. For example,
ROW_TYPE_FIXED can be sent to Innodb */
switch (row_type) {
case ROW_TYPE_COMPACT:
case ROW_TYPE_COMPRESSED:
case ROW_TYPE_DYNAMIC:
case ROW_TYPE_REDUNDANT:
case ROW_TYPE_DEFAULT:
break;
default:
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: invalid ROW_FORMAT specifier.");
ret = FALSE;
}
ut_ad(form != NULL); ut_ad(form != NULL);
ut_ad(create_info != NULL); ut_ad(create_info != NULL);
...@@ -6372,7 +6382,23 @@ create_options_are_valid( ...@@ -6372,7 +6382,23 @@ create_options_are_valid(
case 4: case 4:
case 8: case 8:
case 16: case 16:
/* Valid value. */ /* Valid KEY_BLOCK_SIZE, check its dependencies. */
if (!srv_file_per_table) {
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: KEY_BLOCK_SIZE requires"
" innodb_file_per_table.");
ret = FALSE;
}
if (srv_file_format < DICT_TF_FORMAT_ZIP) {
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: KEY_BLOCK_SIZE requires"
" innodb_file_format > Antelope.");
ret = FALSE;
}
break; break;
default: default:
push_warning_printf( push_warning_printf(
...@@ -6382,72 +6408,43 @@ create_options_are_valid( ...@@ -6382,72 +6408,43 @@ create_options_are_valid(
" Valid values are [1, 2, 4, 8, 16]", " Valid values are [1, 2, 4, 8, 16]",
create_info->key_block_size); create_info->key_block_size);
ret = FALSE; ret = FALSE;
break;
} }
} }
/* If KEY_BLOCK_SIZE was specified, check for its /* Check for a valid Innodb ROW_FORMAT specifier and
dependencies. */ other incompatibilities. */
if (kbs_specified && !srv_file_per_table) { switch (row_format) {
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: KEY_BLOCK_SIZE"
" requires innodb_file_per_table.");
ret = FALSE;
}
if (kbs_specified && srv_file_format < DICT_TF_FORMAT_ZIP) {
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: KEY_BLOCK_SIZE requires"
" innodb_file_format > Antelope.");
ret = FALSE;
}
switch (row_type) {
case ROW_TYPE_COMPRESSED: case ROW_TYPE_COMPRESSED:
case ROW_TYPE_DYNAMIC: CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE;
/* These two ROW_FORMATs require srv_file_per_table CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE;
and srv_file_format > Antelope */
if (!srv_file_per_table) {
push_warning_printf(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: ROW_FORMAT=%s"
" requires innodb_file_per_table.",
get_row_format_name(row_type));
ret = FALSE;
}
if (srv_file_format < DICT_TF_FORMAT_ZIP) {
push_warning_printf(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: ROW_FORMAT=%s requires"
" innodb_file_format > Antelope.",
get_row_format_name(row_type));
ret = FALSE;
}
default:
break; break;
}
switch (row_type) {
case ROW_TYPE_REDUNDANT:
case ROW_TYPE_COMPACT:
case ROW_TYPE_DYNAMIC: case ROW_TYPE_DYNAMIC:
/* KEY_BLOCK_SIZE is only allowed with Compressed or Default */ CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE;
CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE;
/* fall through since dynamic also shuns KBS */
case ROW_TYPE_COMPACT:
case ROW_TYPE_REDUNDANT:
if (kbs_specified) { if (kbs_specified) {
push_warning_printf( push_warning_printf(
thd, MYSQL_ERROR::WARN_LEVEL_WARN, thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: cannot specify ROW_FORMAT = %s" "InnoDB: cannot specify ROW_FORMAT = %s"
" with KEY_BLOCK_SIZE.", " with KEY_BLOCK_SIZE.",
get_row_format_name(row_type)); get_row_format_name(row_format));
ret = FALSE; ret = FALSE;
} }
default: break;
case ROW_TYPE_DEFAULT:
break;
case ROW_TYPE_FIXED:
case ROW_TYPE_PAGE:
case ROW_TYPE_NOT_USED:
push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, \
"InnoDB: invalid ROW_FORMAT specifier.");
ret = FALSE;
break; break;
} }
...@@ -6498,7 +6495,7 @@ ha_innobase::create( ...@@ -6498,7 +6495,7 @@ ha_innobase::create(
const ulint file_format = srv_file_format; const ulint file_format = srv_file_format;
const char* stmt; const char* stmt;
size_t stmt_len; size_t stmt_len;
enum row_type row_type; enum row_type row_format;
DBUG_ENTER("ha_innobase::create"); DBUG_ENTER("ha_innobase::create");
...@@ -6598,8 +6595,8 @@ ha_innobase::create( ...@@ -6598,8 +6595,8 @@ ha_innobase::create(
push_warning( push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN, thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: KEY_BLOCK_SIZE" "InnoDB: KEY_BLOCK_SIZE requires"
" requires innodb_file_per_table."); " innodb_file_per_table.");
flags = 0; flags = 0;
} }
...@@ -6616,20 +6613,19 @@ ha_innobase::create( ...@@ -6616,20 +6613,19 @@ ha_innobase::create(
push_warning_printf( push_warning_printf(
thd, MYSQL_ERROR::WARN_LEVEL_WARN, thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: ignoring" "InnoDB: ignoring KEY_BLOCK_SIZE=%lu.",
" KEY_BLOCK_SIZE=%lu.",
create_info->key_block_size); create_info->key_block_size);
} }
} }
row_type = form->s->row_type; row_format = form->s->row_type;
if (flags) { if (flags) {
/* if ROW_FORMAT is set to default, /* if ROW_FORMAT is set to default,
automatically change it to COMPRESSED.*/ automatically change it to COMPRESSED.*/
if (row_type == ROW_TYPE_DEFAULT) { if (row_format == ROW_TYPE_DEFAULT) {
row_type = ROW_TYPE_COMPRESSED; row_format = ROW_TYPE_COMPRESSED;
} else if (row_type != ROW_TYPE_COMPRESSED) { } else if (row_format != ROW_TYPE_COMPRESSED) {
/* ROW_FORMAT other than COMPRESSED /* ROW_FORMAT other than COMPRESSED
ignores KEY_BLOCK_SIZE. It does not ignores KEY_BLOCK_SIZE. It does not
make sense to reject conflicting make sense to reject conflicting
...@@ -6646,7 +6642,7 @@ ha_innobase::create( ...@@ -6646,7 +6642,7 @@ ha_innobase::create(
} }
} else { } else {
/* flags == 0 means no KEY_BLOCK_SIZE.*/ /* flags == 0 means no KEY_BLOCK_SIZE.*/
if (row_type == ROW_TYPE_COMPRESSED) { if (row_format == ROW_TYPE_COMPRESSED) {
/* ROW_FORMAT=COMPRESSED without /* ROW_FORMAT=COMPRESSED without
KEY_BLOCK_SIZE implies half the KEY_BLOCK_SIZE implies half the
maximum KEY_BLOCK_SIZE. */ maximum KEY_BLOCK_SIZE. */
...@@ -6661,7 +6657,7 @@ ha_innobase::create( ...@@ -6661,7 +6657,7 @@ ha_innobase::create(
} }
} }
switch (row_type) { switch (row_format) {
case ROW_TYPE_REDUNDANT: case ROW_TYPE_REDUNDANT:
break; break;
case ROW_TYPE_COMPRESSED: case ROW_TYPE_COMPRESSED:
...@@ -6672,25 +6668,25 @@ ha_innobase::create( ...@@ -6672,25 +6668,25 @@ ha_innobase::create(
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: ROW_FORMAT=%s requires" "InnoDB: ROW_FORMAT=%s requires"
" innodb_file_per_table.", " innodb_file_per_table.",
get_row_format_name(row_type)); get_row_format_name(row_format));
} else if (file_format < DICT_TF_FORMAT_ZIP) { } else if (file_format < DICT_TF_FORMAT_ZIP) {
push_warning_printf( push_warning_printf(
thd, MYSQL_ERROR::WARN_LEVEL_WARN, thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
"InnoDB: ROW_FORMAT=%s requires" "InnoDB: ROW_FORMAT=%s requires"
" innodb_file_format > Antelope.", " innodb_file_format > Antelope.",
get_row_format_name(row_type)); get_row_format_name(row_format));
} else { } else {
flags |= DICT_TF_COMPACT flags |= DICT_TF_COMPACT
| (DICT_TF_FORMAT_ZIP | (DICT_TF_FORMAT_ZIP
<< DICT_TF_FORMAT_SHIFT); << DICT_TF_FORMAT_SHIFT);
break; break;
} }
/* fall through */ /* fall through */
case ROW_TYPE_NOT_USED: case ROW_TYPE_NOT_USED:
case ROW_TYPE_FIXED: case ROW_TYPE_FIXED:
default: case ROW_TYPE_PAGE:
push_warning( push_warning(
thd, MYSQL_ERROR::WARN_LEVEL_WARN, thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION, ER_ILLEGAL_HA_CREATE_OPTION,
......
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