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)
!(part_buf= generate_partition_syntax(thd, m_part_info,
&part_buf_len,
true,
true,
NULL,
NULL,
NULL)) ||
print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, "error",
......
......@@ -21,13 +21,6 @@
#include "sql_partition.h" /* part_id_range, partition_element */
#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
......
......@@ -394,9 +394,9 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
{
const char *error_string;
if (part_type == RANGE_PARTITION)
error_string= partition_keywords[PKW_RANGE].str;
error_string= "RANGE";
else
error_string= partition_keywords[PKW_LIST].str;
error_string= "LIST";
my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), error_string);
goto end;
}
......
This diff is collapsed.
......@@ -267,11 +267,10 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
bool *partition_changed,
bool *fast_alter_table);
char *generate_partition_syntax(THD *thd, partition_info *part_info,
uint *buf_length, bool use_sql_alloc,
uint *buf_length,
bool show_partition_options,
HA_CREATE_INFO *create_info,
Alter_info *alter_info,
const char *current_comment_start);
Alter_info *alter_info);
bool verify_data_with_partition(TABLE *table, TABLE *part_table,
uint32 part_id);
bool compare_partition_options(HA_CREATE_INFO *table_create_info,
......@@ -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,
const uchar *old_buf);
extern const LEX_STRING partition_keywords[];
#endif /* SQL_PARTITION_INCLUDED */
......@@ -2225,19 +2225,14 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
*/
uint part_syntax_len;
char *part_syntax;
String comment_start;
comment_start.append(STRING_WITH_LEN("\n"));
if ((part_syntax= generate_partition_syntax(thd, table->part_info,
&part_syntax_len,
FALSE,
show_table_options,
NULL, NULL,
comment_start.c_ptr())))
NULL, NULL)))
{
packet->append(comment_start);
packet->append('\n');
if (packet->append(part_syntax, part_syntax_len))
error= 1;
my_free(part_syntax);
}
}
}
......@@ -6822,7 +6817,7 @@ get_partition_column_description(THD *thd,
{
part_column_list_val *col_val= &list_value->col_val_array[i];
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)
tmp_str.append("NULL");
else
......@@ -6899,27 +6894,21 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
case LIST_PARTITION:
tmp_res.length(0);
if (part_info->part_type == RANGE_PARTITION)
tmp_res.append(partition_keywords[PKW_RANGE].str,
partition_keywords[PKW_RANGE].length);
tmp_res.append(STRING_WITH_LEN("RANGE"));
else
tmp_res.append(partition_keywords[PKW_LIST].str,
partition_keywords[PKW_LIST].length);
tmp_res.append(STRING_WITH_LEN("LIST"));
if (part_info->column_list)
tmp_res.append(partition_keywords[PKW_COLUMNS].str,
partition_keywords[PKW_COLUMNS].length);
tmp_res.append(STRING_WITH_LEN(" COLUMNS"));
table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs);
break;
case HASH_PARTITION:
tmp_res.length(0);
if (part_info->linear_hash_ind)
tmp_res.append(partition_keywords[PKW_LINEAR].str,
partition_keywords[PKW_LINEAR].length);
tmp_res.append(STRING_WITH_LEN("LINEAR "));
if (part_info->list_of_part_fields)
tmp_res.append(partition_keywords[PKW_KEY].str,
partition_keywords[PKW_KEY].length);
tmp_res.append(STRING_WITH_LEN("KEY"));
else
tmp_res.append(partition_keywords[PKW_HASH].str,
partition_keywords[PKW_HASH].length);
tmp_res.append(STRING_WITH_LEN("HASH"));
table->field[7]->store(tmp_res.ptr(), tmp_res.length(), cs);
break;
default:
......@@ -6947,14 +6936,11 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
/* Subpartition method */
tmp_res.length(0);
if (part_info->linear_hash_ind)
tmp_res.append(partition_keywords[PKW_LINEAR].str,
partition_keywords[PKW_LINEAR].length);
tmp_res.append(STRING_WITH_LEN("LINEAR "));
if (part_info->list_of_subpart_fields)
tmp_res.append(partition_keywords[PKW_KEY].str,
partition_keywords[PKW_KEY].length);
tmp_res.append(STRING_WITH_LEN("KEY"));
else
tmp_res.append(partition_keywords[PKW_HASH].str,
partition_keywords[PKW_HASH].length);
tmp_res.append(STRING_WITH_LEN("HASH"));
table->field[8]->store(tmp_res.ptr(), tmp_res.length(), cs);
table->field[8]->set_notnull();
......@@ -7003,8 +6989,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
if (part_elem->range_value != LONGLONG_MAX)
table->field[11]->store((longlong) part_elem->range_value, FALSE);
else
table->field[11]->store(partition_keywords[PKW_MAXVALUE].str,
partition_keywords[PKW_MAXVALUE].length, cs);
table->field[11]->store(STRING_WITH_LEN("MAXVALUE"), cs);
}
table->field[11]->set_notnull();
}
......
......@@ -480,6 +480,14 @@ bool String::append(const char *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)
......
......@@ -471,6 +471,7 @@ class String
bool append(const char *s, uint32 arg_length);
bool append(const char *s, uint32 arg_length, CHARSET_INFO *cs);
bool append_ulonglong(ulonglong val);
bool append_longlong(longlong val);
bool append(IO_CACHE* file, uint32 arg_length);
bool append_with_prefill(const char *s, uint32 arg_length,
uint32 full_length, char fill_char);
......
......@@ -1820,11 +1820,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
if (part_info)
{
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len,
TRUE, TRUE,
&syntax_len, TRUE,
lpt->create_info,
lpt->alter_info,
NULL)))
lpt->alter_info)))
{
DBUG_RETURN(TRUE);
}
......@@ -1903,11 +1901,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
TABLE_SHARE *share= lpt->table->s;
char *tmp_part_syntax_str;
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len,
TRUE, TRUE,
&syntax_len, TRUE,
lpt->create_info,
lpt->alter_info,
NULL)))
lpt->alter_info)))
{
error= 1;
goto err;
......@@ -4548,11 +4544,9 @@ handler *mysql_create_frm_image(THD *thd,
for syntax stored in frm file.
*/
if (!(part_syntax_buf= generate_partition_syntax(thd, part_info,
&syntax_len,
TRUE, TRUE,
&syntax_len, TRUE,
create_info,
alter_info,
NULL)))
alter_info)))
goto err;
part_info->part_info_string= part_syntax_buf;
part_info->part_info_len= syntax_len;
......
......@@ -8573,7 +8573,7 @@ int spider_discover_table_structure(
}
#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT
if (!(part_syntax = generate_partition_syntax(thd, part_info, &part_syntax_len,
FALSE, TRUE, info, NULL, NULL)))
TRUE, info, NULL)))
#else
if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,
FALSE, TRUE, info, NULL)))
......@@ -8586,7 +8586,6 @@ int spider_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str.q_append(part_syntax, part_syntax_len);
my_free(part_syntax, MYF(0));
}
#endif
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