Commit 504eff0c authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: generate_partition_syntax()

Don't write to a temporary file, use String.
Remove strange one-liner "helpers", use String methods.
Don't use current_thd, don't allocate memory for 1-byte strings, etc.
parent 03c52e96
...@@ -9053,8 +9053,6 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt) ...@@ -9053,8 +9053,6 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt)
!(part_buf= generate_partition_syntax(thd, m_part_info, !(part_buf= generate_partition_syntax(thd, m_part_info,
&part_buf_len, &part_buf_len,
true, true,
true,
NULL,
NULL, NULL,
NULL)) || NULL)) ||
print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, "error", print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, "error",
......
...@@ -21,13 +21,6 @@ ...@@ -21,13 +21,6 @@
#include "sql_partition.h" /* part_id_range, partition_element */ #include "sql_partition.h" /* part_id_range, partition_element */
#include "queues.h" /* QUEUE */ #include "queues.h" /* QUEUE */
enum partition_keywords
{
PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR,
PKW_COLUMNS, PKW_ALGORITHM
};
#define PARTITION_BYTES_IN_POS 2 #define PARTITION_BYTES_IN_POS 2
......
...@@ -394,9 +394,9 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file, ...@@ -394,9 +394,9 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
{ {
const char *error_string; const char *error_string;
if (part_type == RANGE_PARTITION) if (part_type == RANGE_PARTITION)
error_string= partition_keywords[PKW_RANGE].str; error_string= "RANGE";
else else
error_string= partition_keywords[PKW_LIST].str; error_string= "LIST";
my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), error_string); my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), error_string);
goto end; goto end;
} }
......
This diff is collapsed.
...@@ -267,11 +267,10 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, ...@@ -267,11 +267,10 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
bool *partition_changed, bool *partition_changed,
bool *fast_alter_table); bool *fast_alter_table);
char *generate_partition_syntax(THD *thd, partition_info *part_info, char *generate_partition_syntax(THD *thd, partition_info *part_info,
uint *buf_length, bool use_sql_alloc, uint *buf_length,
bool show_partition_options, bool show_partition_options,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
Alter_info *alter_info, Alter_info *alter_info);
const char *current_comment_start);
bool verify_data_with_partition(TABLE *table, TABLE *part_table, bool verify_data_with_partition(TABLE *table, TABLE *part_table,
uint32 part_id); uint32 part_id);
bool compare_partition_options(HA_CREATE_INFO *table_create_info, bool compare_partition_options(HA_CREATE_INFO *table_create_info,
...@@ -291,6 +290,4 @@ void create_subpartition_name(char *out, const char *in1, ...@@ -291,6 +290,4 @@ void create_subpartition_name(char *out, const char *in1,
void set_key_field_ptr(KEY *key_info, const uchar *new_buf, void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
const uchar *old_buf); const uchar *old_buf);
extern const LEX_STRING partition_keywords[];
#endif /* SQL_PARTITION_INCLUDED */ #endif /* SQL_PARTITION_INCLUDED */
...@@ -2225,19 +2225,14 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -2225,19 +2225,14 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
*/ */
uint part_syntax_len; uint part_syntax_len;
char *part_syntax; char *part_syntax;
String comment_start;
comment_start.append(STRING_WITH_LEN("\n"));
if ((part_syntax= generate_partition_syntax(thd, table->part_info, if ((part_syntax= generate_partition_syntax(thd, table->part_info,
&part_syntax_len, &part_syntax_len,
FALSE,
show_table_options, show_table_options,
NULL, NULL, NULL, NULL)))
comment_start.c_ptr())))
{ {
packet->append(comment_start); packet->append('\n');
if (packet->append(part_syntax, part_syntax_len)) if (packet->append(part_syntax, part_syntax_len))
error= 1; error= 1;
my_free(part_syntax);
} }
} }
} }
...@@ -6822,7 +6817,7 @@ get_partition_column_description(THD *thd, ...@@ -6822,7 +6817,7 @@ get_partition_column_description(THD *thd,
{ {
part_column_list_val *col_val= &list_value->col_val_array[i]; part_column_list_val *col_val= &list_value->col_val_array[i];
if (col_val->max_value) if (col_val->max_value)
tmp_str.append(partition_keywords[PKW_MAXVALUE].str); tmp_str.append(STRING_WITH_LEN("MAXVALUE"));
else if (col_val->null_value) else if (col_val->null_value)
tmp_str.append("NULL"); tmp_str.append("NULL");
else else
...@@ -6899,27 +6894,21 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -6899,27 +6894,21 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
case LIST_PARTITION: case LIST_PARTITION:
tmp_res.length(0); tmp_res.length(0);
if (part_info->part_type == RANGE_PARTITION) if (part_info->part_type == RANGE_PARTITION)
tmp_res.append(partition_keywords[PKW_RANGE].str, tmp_res.append(STRING_WITH_LEN("RANGE"));
partition_keywords[PKW_RANGE].length);
else else
tmp_res.append(partition_keywords[PKW_LIST].str, tmp_res.append(STRING_WITH_LEN("LIST"));
partition_keywords[PKW_LIST].length);
if (part_info->column_list) if (part_info->column_list)
tmp_res.append(partition_keywords[PKW_COLUMNS].str, tmp_res.append(STRING_WITH_LEN(" COLUMNS"));
partition_keywords[PKW_COLUMNS].length);
table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs); table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs);
break; break;
case HASH_PARTITION: case HASH_PARTITION:
tmp_res.length(0); tmp_res.length(0);
if (part_info->linear_hash_ind) if (part_info->linear_hash_ind)
tmp_res.append(partition_keywords[PKW_LINEAR].str, tmp_res.append(STRING_WITH_LEN("LINEAR "));
partition_keywords[PKW_LINEAR].length);
if (part_info->list_of_part_fields) if (part_info->list_of_part_fields)
tmp_res.append(partition_keywords[PKW_KEY].str, tmp_res.append(STRING_WITH_LEN("KEY"));
partition_keywords[PKW_KEY].length);
else else
tmp_res.append(partition_keywords[PKW_HASH].str, tmp_res.append(STRING_WITH_LEN("HASH"));
partition_keywords[PKW_HASH].length);
table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs); table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs);
break; break;
default: default:
...@@ -6947,14 +6936,11 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -6947,14 +6936,11 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
/* Subpartition method */ /* Subpartition method */
tmp_res.length(0); tmp_res.length(0);
if (part_info->linear_hash_ind) if (part_info->linear_hash_ind)
tmp_res.append(partition_keywords[PKW_LINEAR].str, tmp_res.append(STRING_WITH_LEN("LINEAR "));
partition_keywords[PKW_LINEAR].length);
if (part_info->list_of_subpart_fields) if (part_info->list_of_subpart_fields)
tmp_res.append(partition_keywords[PKW_KEY].str, tmp_res.append(STRING_WITH_LEN("KEY"));
partition_keywords[PKW_KEY].length);
else else
tmp_res.append(partition_keywords[PKW_HASH].str, tmp_res.append(STRING_WITH_LEN("HASH"));
partition_keywords[PKW_HASH].length);
table->field[8]->store(tmp_res.ptr(), tmp_res.length(), cs); table->field[8]->store(tmp_res.ptr(), tmp_res.length(), cs);
table->field[8]->set_notnull(); table->field[8]->set_notnull();
...@@ -7003,8 +6989,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -7003,8 +6989,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
if (part_elem->range_value != LONGLONG_MAX) if (part_elem->range_value != LONGLONG_MAX)
table->field[11]->store((longlong) part_elem->range_value, FALSE); table->field[11]->store((longlong) part_elem->range_value, FALSE);
else else
table->field[11]->store(partition_keywords[PKW_MAXVALUE].str, table->field[11]->store(STRING_WITH_LEN("MAXVALUE"), cs);
partition_keywords[PKW_MAXVALUE].length, cs);
} }
table->field[11]->set_notnull(); table->field[11]->set_notnull();
} }
......
...@@ -480,6 +480,14 @@ bool String::append(const char *s) ...@@ -480,6 +480,14 @@ bool String::append(const char *s)
return append(s, (uint) strlen(s)); return append(s, (uint) strlen(s));
} }
bool String::append_longlong(longlong val)
{
if (realloc(str_length+MAX_BIGINT_WIDTH+2))
return TRUE;
char *end= (char*) longlong10_to_str(val, (char*) Ptr + str_length, -10);
str_length= end - Ptr;
return FALSE;
}
bool String::append_ulonglong(ulonglong val) bool String::append_ulonglong(ulonglong val)
......
...@@ -471,6 +471,7 @@ class String ...@@ -471,6 +471,7 @@ class String
bool append(const char *s, uint32 arg_length); bool append(const char *s, uint32 arg_length);
bool append(const char *s, uint32 arg_length, CHARSET_INFO *cs); bool append(const char *s, uint32 arg_length, CHARSET_INFO *cs);
bool append_ulonglong(ulonglong val); bool append_ulonglong(ulonglong val);
bool append_longlong(longlong val);
bool append(IO_CACHE* file, uint32 arg_length); bool append(IO_CACHE* file, uint32 arg_length);
bool append_with_prefill(const char *s, uint32 arg_length, bool append_with_prefill(const char *s, uint32 arg_length,
uint32 full_length, char fill_char); uint32 full_length, char fill_char);
......
...@@ -1820,11 +1820,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) ...@@ -1820,11 +1820,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
if (part_info) if (part_info)
{ {
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info, if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len, &syntax_len, TRUE,
TRUE, TRUE,
lpt->create_info, lpt->create_info,
lpt->alter_info, lpt->alter_info)))
NULL)))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
...@@ -1903,11 +1901,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) ...@@ -1903,11 +1901,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
TABLE_SHARE *share= lpt->table->s; TABLE_SHARE *share= lpt->table->s;
char *tmp_part_syntax_str; char *tmp_part_syntax_str;
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info, if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len, &syntax_len, TRUE,
TRUE, TRUE,
lpt->create_info, lpt->create_info,
lpt->alter_info, lpt->alter_info)))
NULL)))
{ {
error= 1; error= 1;
goto err; goto err;
...@@ -4548,11 +4544,9 @@ handler *mysql_create_frm_image(THD *thd, ...@@ -4548,11 +4544,9 @@ handler *mysql_create_frm_image(THD *thd,
for syntax stored in frm file. for syntax stored in frm file.
*/ */
if (!(part_syntax_buf= generate_partition_syntax(thd, part_info, if (!(part_syntax_buf= generate_partition_syntax(thd, part_info,
&syntax_len, &syntax_len, TRUE,
TRUE, TRUE,
create_info, create_info,
alter_info, alter_info)))
NULL)))
goto err; goto err;
part_info->part_info_string= part_syntax_buf; part_info->part_info_string= part_syntax_buf;
part_info->part_info_len= syntax_len; part_info->part_info_len= syntax_len;
......
...@@ -8573,7 +8573,7 @@ int spider_discover_table_structure( ...@@ -8573,7 +8573,7 @@ int spider_discover_table_structure(
} }
#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT
if (!(part_syntax = generate_partition_syntax(thd, part_info, &part_syntax_len, if (!(part_syntax = generate_partition_syntax(thd, part_info, &part_syntax_len,
FALSE, TRUE, info, NULL, NULL))) TRUE, info, NULL)))
#else #else
if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len, if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,
FALSE, TRUE, info, NULL))) FALSE, TRUE, info, NULL)))
...@@ -8586,7 +8586,6 @@ int spider_discover_table_structure( ...@@ -8586,7 +8586,6 @@ int spider_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
} }
str.q_append(part_syntax, part_syntax_len); str.q_append(part_syntax, part_syntax_len);
my_free(part_syntax, MYF(0));
} }
#endif #endif
DBUG_PRINT("info",("spider str=%s", str.c_ptr_safe())); DBUG_PRINT("info",("spider str=%s", str.c_ptr_safe()));
......
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