summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/ha_partition.cc2
-rw-r--r--sql/ha_partition.h7
-rw-r--r--sql/partition_info.cc4
-rw-r--r--sql/sql_partition.cc530
-rw-r--r--sql/sql_partition.h7
-rw-r--r--sql/sql_show.cc41
-rw-r--r--sql/sql_string.cc8
-rw-r--r--sql/sql_string.h1
-rw-r--r--sql/sql_table.cc18
-rw-r--r--storage/spider/spd_table.cc3
10 files changed, 170 insertions, 451 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 7f156c80205..6099f40ba0c 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -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",
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 70cd3760783..a5a584287cf 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -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
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 24506434a76..b2588c375e5 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -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;
}
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 0a146aeb12b..c3f2d8ec14e 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -83,27 +83,6 @@ using std::min;
/*
Partition related functions declarations and some static constants;
*/
-const LEX_STRING partition_keywords[]=
-{
- { C_STRING_WITH_LEN("HASH") },
- { C_STRING_WITH_LEN("RANGE") },
- { C_STRING_WITH_LEN("LIST") },
- { C_STRING_WITH_LEN("KEY") },
- { C_STRING_WITH_LEN("MAXVALUE") },
- { C_STRING_WITH_LEN("LINEAR ") },
- { C_STRING_WITH_LEN(" COLUMNS") },
- { C_STRING_WITH_LEN("ALGORITHM") }
-
-};
-static const char *part_str= "PARTITION";
-static const char *sub_str= "SUB";
-static const char *by_str= "BY";
-static const char *space_str= " ";
-static const char *equal_str= "=";
-static const char *end_paren_str= ")";
-static const char *begin_paren_str= "(";
-static const char *comma_str= ",";
-
static int get_partition_id_list_col(partition_info *, uint32 *, longlong *);
static int get_partition_id_list(partition_info *, uint32 *, longlong *);
static int get_partition_id_range_col(partition_info *, uint32 *, longlong *);
@@ -1675,13 +1654,13 @@ bool fix_partition_func(THD *thd, TABLE *table,
part_info->fixed= TRUE;
if (part_info->part_type == RANGE_PARTITION)
{
- error_str= partition_keywords[PKW_RANGE].str;
+ error_str= "HASH";
if (unlikely(part_info->check_range_constants(thd)))
goto end;
}
else if (part_info->part_type == LIST_PARTITION)
{
- error_str= partition_keywords[PKW_LIST].str;
+ error_str= "LIST";
if (unlikely(part_info->check_list_constants(thd)))
goto end;
}
@@ -1759,160 +1738,48 @@ end:
ALTER TABLE commands. Finally it is used for SHOW CREATE TABLES.
*/
-static int add_write(File fptr, const char *buf, uint len)
-{
- uint ret_code= mysql_file_write(fptr, (const uchar*)buf, len, MYF(MY_FNABP));
-
- if (likely(ret_code == 0))
- return 0;
- else
- return 1;
-}
-
-static int add_string_object(File fptr, String *string)
-{
- return add_write(fptr, string->ptr(), string->length());
-}
-
-static int add_string(File fptr, const char *string)
-{
- return add_write(fptr, string, strlen(string));
-}
-
-static int add_string_len(File fptr, const char *string, uint len)
-{
- return add_write(fptr, string, len);
-}
-
-static int add_space(File fptr)
-{
- return add_string(fptr, space_str);
-}
-
-static int add_comma(File fptr)
-{
- return add_string(fptr, comma_str);
-}
-
-static int add_equal(File fptr)
-{
- return add_string(fptr, equal_str);
-}
-
-static int add_end_parenthesis(File fptr)
-{
- return add_string(fptr, end_paren_str);
-}
-
-static int add_begin_parenthesis(File fptr)
+static int add_part_field_list(THD *thd, String *str, List<char> field_list)
{
- return add_string(fptr, begin_paren_str);
-}
-
-static int add_part_key_word(File fptr, const char *key_string)
-{
- int err= add_string(fptr, key_string);
- err+= add_space(fptr);
- return err;
-}
-
-static int add_partition(File fptr)
-{
- char buff[22];
- strxmov(buff, part_str, space_str, NullS);
- return add_string(fptr, buff);
-}
-
-static int add_subpartition(File fptr)
-{
- int err= add_string(fptr, sub_str);
-
- return err + add_partition(fptr);
-}
-
-static int add_partition_by(File fptr)
-{
- char buff[22];
- strxmov(buff, part_str, space_str, by_str, space_str, NullS);
- return add_string(fptr, buff);
-}
-
-static int add_subpartition_by(File fptr)
-{
- int err= add_string(fptr, sub_str);
-
- return err + add_partition_by(fptr);
-}
-
-static int add_part_field_list(File fptr, List<char> field_list)
-{
- uint i, num_fields;
int err= 0;
-
+ const char *field_name;
List_iterator<char> part_it(field_list);
- num_fields= field_list.elements;
- i= 0;
- err+= add_begin_parenthesis(fptr);
- while (i < num_fields)
- {
- const char *field_str= part_it++;
- String field_string("", 0, system_charset_info);
- THD *thd= current_thd;
- ulonglong save_options= thd->variables.option_bits;
- thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE;
- append_identifier(thd, &field_string, field_str,
- strlen(field_str));
- thd->variables.option_bits= save_options;
- err+= add_string_object(fptr, &field_string);
- if (i != (num_fields-1))
- err+= add_comma(fptr);
- i++;
- }
- err+= add_end_parenthesis(fptr);
- return err;
-}
-static int add_name_string(File fptr, const char *name)
-{
- int err;
- String name_string("", 0, system_charset_info);
- THD *thd= current_thd;
- ulonglong save_options= thd->variables.option_bits;
- thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE;
- append_identifier(thd, &name_string, name,
- strlen(name));
- thd->variables.option_bits= save_options;
- err= add_string_object(fptr, &name_string);
+ err+= str->append('(');
+ while ((field_name= part_it++))
+ {
+ err+= append_identifier(thd, str, field_name, strlen(field_name));
+ err+= str->append(',');
+ }
+ if (field_list.elements)
+ str->length(str->length()-1);
+ err+= str->append(')');
return err;
}
-static int add_int(File fptr, longlong number)
-{
- char buff[32];
- llstr(number, buff);
- return add_string(fptr, buff);
-}
-
-static int add_uint(File fptr, ulonglong number)
-{
- char buff[32];
- longlong2str(number, buff, 10);
- return add_string(fptr, buff);
-}
-
/*
Must escape strings in partitioned tables frm-files,
parsing it later with mysql_unpack_partition will fail otherwise.
*/
-static int add_quoted_string(File fptr, const char *quotestr)
+
+static int add_keyword_string(String *str, const char *keyword,
+ bool quoted, const char *keystr)
{
- String escapedstr;
- int err= add_string(fptr, "'");
- err+= escapedstr.append_for_single_quote(quotestr);
- err+= add_string(fptr, escapedstr.c_ptr_safe());
- return err + add_string(fptr, "'");
+ int err= str->append(' ');
+ err+= str->append(keyword);
+
+ str->append(STRING_WITH_LEN(" = "));
+ if (quoted)
+ {
+ err+= str->append('\'');
+ err+= str->append_for_single_quote(keystr);
+ err+= str->append('\'');
+ }
+ else
+ err+= str->append(keystr);
+ return err;
}
+
/**
@brief Truncate the partition file name from a path it it exists.
@@ -1945,7 +1812,6 @@ void truncate_partition_filename(char *path)
}
}
-
/**
@brief Output a filepath. Similar to add_keyword_string except it
also converts \ to / on Windows and skips the partition file name at
@@ -1957,15 +1823,9 @@ table. So when the storage engine is asked for the DATA DIRECTORY string
after a restart through Handler::update_create_options(), the storage
engine may include the filename.
*/
-static int add_keyword_path(File fptr, const char *keyword,
+static int add_keyword_path(String *str, const char *keyword,
const char *path)
{
- int err= add_string(fptr, keyword);
-
- err+= add_space(fptr);
- err+= add_equal(fptr);
- err+= add_space(fptr);
-
char temp_path[FN_REFLEN];
strcpy(temp_path, path);
#ifdef __WIN__
@@ -1985,73 +1845,44 @@ static int add_keyword_path(File fptr, const char *keyword,
*/
truncate_partition_filename(temp_path);
- err+= add_quoted_string(fptr, temp_path);
-
- return err + add_space(fptr);
-}
-
-static int add_keyword_string(File fptr, const char *keyword,
- bool should_use_quotes,
- const char *keystr)
-{
- int err= add_string(fptr, keyword);
-
- err+= add_space(fptr);
- err+= add_equal(fptr);
- err+= add_space(fptr);
- if (should_use_quotes)
- err+= add_quoted_string(fptr, keystr);
- else
- err+= add_string(fptr, keystr);
- return err + add_space(fptr);
-}
-
-static int add_keyword_int(File fptr, const char *keyword, longlong num)
-{
- int err= add_string(fptr, keyword);
-
- err+= add_space(fptr);
- err+= add_equal(fptr);
- err+= add_space(fptr);
- err+= add_int(fptr, num);
- return err + add_space(fptr);
+ return add_keyword_string(str, keyword, true, temp_path);
}
-static int add_engine(File fptr, handlerton *engine_type)
+static int add_keyword_int(String *str, const char *keyword, longlong num)
{
- const char *engine_str= ha_resolve_storage_engine_name(engine_type);
- DBUG_PRINT("info", ("ENGINE: %s", engine_str));
- int err= add_string(fptr, "ENGINE = ");
- return err + add_string(fptr, engine_str);
+ int err= str->append(' ');
+ err+= str->append(keyword);
+ str->append(STRING_WITH_LEN(" = "));
+ return err + str->append_longlong(num);
}
-static int add_partition_options(File fptr, partition_element *p_elem)
+static int add_partition_options(String *str, partition_element *p_elem)
{
int err= 0;
- err+= add_space(fptr);
if (p_elem->tablespace_name)
- err+= add_keyword_string(fptr,"TABLESPACE", FALSE,
- p_elem->tablespace_name);
+ err+= add_keyword_string(str,"TABLESPACE", false, p_elem->tablespace_name);
if (p_elem->nodegroup_id != UNDEF_NODEGROUP)
- err+= add_keyword_int(fptr,"NODEGROUP",(longlong)p_elem->nodegroup_id);
+ err+= add_keyword_int(str,"NODEGROUP",(longlong)p_elem->nodegroup_id);
if (p_elem->part_max_rows)
- err+= add_keyword_int(fptr,"MAX_ROWS",(longlong)p_elem->part_max_rows);
+ err+= add_keyword_int(str,"MAX_ROWS",(longlong)p_elem->part_max_rows);
if (p_elem->part_min_rows)
- err+= add_keyword_int(fptr,"MIN_ROWS",(longlong)p_elem->part_min_rows);
+ err+= add_keyword_int(str,"MIN_ROWS",(longlong)p_elem->part_min_rows);
if (!(current_thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE))
{
if (p_elem->data_file_name)
- err+= add_keyword_path(fptr, "DATA DIRECTORY", p_elem->data_file_name);
+ err+= add_keyword_path(str, "DATA DIRECTORY", p_elem->data_file_name);
if (p_elem->index_file_name)
- err+= add_keyword_path(fptr, "INDEX DIRECTORY", p_elem->index_file_name);
+ err+= add_keyword_path(str, "INDEX DIRECTORY", p_elem->index_file_name);
}
if (p_elem->part_comment)
- err+= add_keyword_string(fptr, "COMMENT", TRUE, p_elem->part_comment);
+ err+= add_keyword_string(str, "COMMENT", true, p_elem->part_comment);
if (p_elem->connect_string.length)
- err+= add_keyword_string(fptr, "CONNECTION", TRUE,
+ err+= add_keyword_string(str, "CONNECTION", true,
p_elem->connect_string.str);
- return err + add_engine(fptr,p_elem->engine_type);
+ err += add_keyword_string(str, "ENGINE", false,
+ ha_resolve_storage_engine_name(p_elem->engine_type));
+ return err;
}
@@ -2162,7 +1993,7 @@ static Create_field* get_sql_field(char *field_name,
}
-static int add_column_list_values(File fptr, partition_info *part_info,
+static int add_column_list_values(String *str, partition_info *part_info,
part_elem_value *list_value,
HA_CREATE_INFO *create_info,
Alter_info *alter_info)
@@ -2175,25 +2006,22 @@ static int add_column_list_values(File fptr, partition_info *part_info,
part_info->num_columns > 1U);
if (use_parenthesis)
- err+= add_begin_parenthesis(fptr);
+ err+= str->append('(');
for (i= 0; i < num_elements; i++)
{
part_column_list_val *col_val= &list_value->col_val_array[i];
char *field_name= it++;
if (col_val->max_value)
- err+= add_string(fptr, partition_keywords[PKW_MAXVALUE].str);
+ err+= str->append(STRING_WITH_LEN("MAXVALUE"));
else if (col_val->null_value)
- err+= add_string(fptr, "NULL");
+ err+= str->append(STRING_WITH_LEN("NULL"));
else
{
- char buffer[MAX_KEY_LENGTH];
- String str(buffer, sizeof(buffer), &my_charset_bin);
Item *item_expr= col_val->item_expression;
if (item_expr->null_value)
- err+= add_string(fptr, "NULL");
+ err+= str->append(STRING_WITH_LEN("NULL"));
else
{
- String *res;
CHARSET_INFO *field_cs;
bool need_cs_check= FALSE;
Item_result result_type= STRING_RESULT;
@@ -2254,27 +2082,28 @@ static int add_column_list_values(File fptr, partition_info *part_info,
}
}
{
- String val_conv;
+ StringBuffer<MAX_KEY_LENGTH> buf;
+ String val_conv, *res;
val_conv.set_charset(system_charset_info);
- res= item_expr->val_str(&str);
+ res= item_expr->val_str(&buf);
if (get_cs_converted_part_value_from_string(current_thd,
item_expr, res,
&val_conv, field_cs,
(bool)(alter_info != NULL)))
return 1;
- err+= add_string_object(fptr, &val_conv);
+ err+= str->append(val_conv);
}
}
}
if (i != (num_elements - 1))
- err+= add_string(fptr, comma_str);
+ err+= str->append(',');
}
if (use_parenthesis)
- err+= add_end_parenthesis(fptr);
+ err+= str->append(')');
return err;
}
-static int add_partition_values(File fptr, partition_info *part_info,
+static int add_partition_values(String *str, partition_info *part_info,
partition_element *p_elem,
HA_CREATE_INFO *create_info,
Alter_info *alter_info)
@@ -2283,29 +2112,29 @@ static int add_partition_values(File fptr, partition_info *part_info,
if (part_info->part_type == RANGE_PARTITION)
{
- err+= add_string(fptr, " VALUES LESS THAN ");
+ err+= str->append(STRING_WITH_LEN(" VALUES LESS THAN "));
if (part_info->column_list)
{
List_iterator<part_elem_value> list_val_it(p_elem->list_val_list);
part_elem_value *list_value= list_val_it++;
- err+= add_begin_parenthesis(fptr);
- err+= add_column_list_values(fptr, part_info, list_value,
+ err+= str->append('(');
+ err+= add_column_list_values(str, part_info, list_value,
create_info, alter_info);
- err+= add_end_parenthesis(fptr);
+ err+= str->append(')');
}
else
{
if (!p_elem->max_value)
{
- err+= add_begin_parenthesis(fptr);
+ err+= str->append('(');
if (p_elem->signed_flag)
- err+= add_int(fptr, p_elem->range_value);
+ err+= str->append_longlong(p_elem->range_value);
else
- err+= add_uint(fptr, p_elem->range_value);
- err+= add_end_parenthesis(fptr);
+ err+= str->append_ulonglong(p_elem->range_value);
+ err+= str->append(')');
}
else
- err+= add_string(fptr, partition_keywords[PKW_MAXVALUE].str);
+ err+= str->append(STRING_WITH_LEN("MAXVALUE"));
}
}
else if (part_info->part_type == LIST_PARTITION)
@@ -2317,23 +2146,23 @@ static int add_partition_values(File fptr, partition_info *part_info,
{
DBUG_ASSERT(part_info->defined_max_value ||
current_thd->lex->sql_command == SQLCOM_ALTER_TABLE);
- err+= add_string(fptr, " DEFAULT");
+ err+= str->append(STRING_WITH_LEN(" DEFAULT"));
return err;
}
- err+= add_string(fptr, " VALUES IN ");
+ err+= str->append(STRING_WITH_LEN(" VALUES IN "));
uint num_items= p_elem->list_val_list.elements;
- err+= add_begin_parenthesis(fptr);
+ err+= str->append('(');
if (p_elem->has_null_value)
{
- err+= add_string(fptr, "NULL");
+ err+= str->append(STRING_WITH_LEN("NULL"));
if (num_items == 0)
{
- err+= add_end_parenthesis(fptr);
+ err+= str->append(')');
goto end;
}
- err+= add_comma(fptr);
+ err+= str->append(',');
}
i= 0;
do
@@ -2341,19 +2170,19 @@ static int add_partition_values(File fptr, partition_info *part_info,
part_elem_value *list_value= list_val_it++;
if (part_info->column_list)
- err+= add_column_list_values(fptr, part_info, list_value,
+ err+= add_column_list_values(str, part_info, list_value,
create_info, alter_info);
else
{
if (!list_value->unsigned_flag)
- err+= add_int(fptr, list_value->value);
+ err+= str->append_longlong(list_value->value);
else
- err+= add_uint(fptr, list_value->value);
+ err+= str->append_ulonglong(list_value->value);
}
if (i != (num_items-1))
- err+= add_comma(fptr);
+ err+= str->append(',');
} while (++i < num_items);
- err+= add_end_parenthesis(fptr);
+ err+= str->append(')');
}
end:
return err;
@@ -2363,49 +2192,24 @@ end:
/**
Add 'KEY' word, with optional 'ALGORTIHM = N'.
- @param fptr File to write to.
+ @param str String to write to.
@param part_info partition_info holding the used key_algorithm
- @param current_comment_start NULL, or comment string encapsulating the
- PARTITION BY clause.
@return Operation status.
@retval 0 Success
@retval != 0 Failure
*/
-static int add_key_with_algorithm(File fptr, partition_info *part_info,
- const char *current_comment_start)
+static int add_key_with_algorithm(String *str, partition_info *part_info)
{
int err= 0;
- err+= add_part_key_word(fptr, partition_keywords[PKW_KEY].str);
+ err+= str->append(STRING_WITH_LEN("KEY "));
- /*
- current_comment_start is given when called from SHOW CREATE TABLE,
- Then only add ALGORITHM = 1, not the default 2 or non-set 0!
- For .frm current_comment_start is NULL, then add ALGORITHM if != 0.
- */
- if (part_info->key_algorithm == partition_info::KEY_ALGORITHM_51 || // SHOW
- (!current_comment_start && // .frm
- (part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE)))
- {
- /* If we already are within a comment, end that comment first. */
- if (current_comment_start)
- err+= add_string(fptr, "*/ ");
- err+= add_string(fptr, "/*!50611 ");
- err+= add_part_key_word(fptr, partition_keywords[PKW_ALGORITHM].str);
- err+= add_equal(fptr);
- err+= add_space(fptr);
- err+= add_int(fptr, part_info->key_algorithm);
- err+= add_space(fptr);
- err+= add_string(fptr, "*/ ");
- if (current_comment_start)
- {
- /* Skip new line. */
- if (current_comment_start[0] == '\n')
- current_comment_start++;
- err+= add_string(fptr, current_comment_start);
- err+= add_space(fptr);
- }
+ if (part_info->key_algorithm == partition_info::KEY_ALGORITHM_51)
+ {
+ err+= str->append(STRING_WITH_LEN("ALGORITHM = "));
+ err+= str->append_longlong(part_info->key_algorithm);
+ err+= str->append(' ');
}
return err;
}
@@ -2420,8 +2224,6 @@ static int add_key_with_algorithm(File fptr, partition_info *part_info,
generate_partition_syntax()
part_info The partitioning data structure
buf_length A pointer to the returned buffer length
- use_sql_alloc Allocate buffer from sql_alloc if true
- otherwise use my_malloc
show_partition_options Should we display partition options
create_info Info generated by parser
alter_info Info generated by parser
@@ -2438,64 +2240,45 @@ static int add_key_with_algorithm(File fptr, partition_info *part_info,
type ALTER TABLE commands focusing on changing the PARTITION structure
in any fashion.
- The implementation writes the syntax to a temporary file (essentially
- an abstraction of a dynamic array) and if all writes goes well it
- allocates a buffer and writes the syntax into this one and returns it.
-
- As a security precaution the file is deleted before writing into it. This
- means that no other processes on the machine can open and read the file
- while this processing is ongoing.
-
The code is optimised for minimal code size since it is not used in any
common queries.
*/
char *generate_partition_syntax(THD *thd, partition_info *part_info,
uint *buf_length,
- bool use_sql_alloc,
bool show_partition_options,
HA_CREATE_INFO *create_info,
- Alter_info *alter_info,
- const char *current_comment_start)
+ Alter_info *alter_info)
{
uint i,j, tot_num_parts, num_subparts;
partition_element *part_elem;
- ulonglong buffer_length;
- char path[FN_REFLEN];
int err= 0;
List_iterator<partition_element> part_it(part_info->partitions);
- File fptr;
- char *buf= NULL; //Return buffer
+ ulonglong save_options= thd->variables.option_bits;
+ StringBuffer<1024> str;
DBUG_ENTER("generate_partition_syntax");
- if (unlikely(((fptr= create_temp_file(path,mysql_tmpdir,"psy",
- O_RDWR | O_BINARY | O_TRUNC |
- O_TEMPORARY, MYF(MY_WME)))) < 0))
- DBUG_RETURN(NULL);
-#ifndef __WIN__
- unlink(path);
-#endif
- err+= add_space(fptr);
- err+= add_partition_by(fptr);
+ thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE;
+
+ err+= str.append(STRING_WITH_LEN(" PARTITION BY "));
switch (part_info->part_type)
{
case RANGE_PARTITION:
- err+= add_part_key_word(fptr, partition_keywords[PKW_RANGE].str);
+ err+= str.append(STRING_WITH_LEN("RANGE "));
break;
case LIST_PARTITION:
- err+= add_part_key_word(fptr, partition_keywords[PKW_LIST].str);
+ err+= str.append(STRING_WITH_LEN("LIST "));
break;
case HASH_PARTITION:
if (part_info->linear_hash_ind)
- err+= add_string(fptr, partition_keywords[PKW_LINEAR].str);
+ err+= str.append(STRING_WITH_LEN("LINEAR "));
if (part_info->list_of_part_fields)
{
- err+= add_key_with_algorithm(fptr, part_info,
- current_comment_start);
- err+= add_part_field_list(fptr, part_info->part_field_list);
+ err+= add_key_with_algorithm(&str, part_info);
+ err+= add_part_field_list(thd, &str, part_info->part_field_list);
}
else
- err+= add_part_key_word(fptr, partition_keywords[PKW_HASH].str);
+ err+= str.append(STRING_WITH_LEN("HASH "));
break;
default:
DBUG_ASSERT(0);
@@ -2505,51 +2288,45 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
}
if (part_info->part_expr)
{
- err+= add_begin_parenthesis(fptr);
- err+= add_string_len(fptr, part_info->part_func_string,
- part_info->part_func_len);
- err+= add_end_parenthesis(fptr);
+ err+= str.append('(');
+ err+= str.append(part_info->part_func_string, part_info->part_func_len);
+ err+= str.append(')');
}
else if (part_info->column_list)
{
- err+= add_string(fptr, partition_keywords[PKW_COLUMNS].str);
- err+= add_part_field_list(fptr, part_info->part_field_list);
+ err+= str.append(STRING_WITH_LEN(" COLUMNS"));
+ err+= add_part_field_list(thd, &str, part_info->part_field_list);
}
if ((!part_info->use_default_num_partitions) &&
part_info->use_default_partitions)
{
- err+= add_string(fptr, "\n");
- err+= add_string(fptr, "PARTITIONS ");
- err+= add_int(fptr, part_info->num_parts);
+ err+= str.append(STRING_WITH_LEN("\nPARTITIONS "));
+ err+= str.append_ulonglong(part_info->num_parts);
}
if (part_info->is_sub_partitioned())
{
- err+= add_string(fptr, "\n");
- err+= add_subpartition_by(fptr);
+ err+= str.append(STRING_WITH_LEN("\nSUBPARTITION BY "));
/* Must be hash partitioning for subpartitioning */
if (part_info->linear_hash_ind)
- err+= add_string(fptr, partition_keywords[PKW_LINEAR].str);
+ err+= str.append(STRING_WITH_LEN("LINEAR "));
if (part_info->list_of_subpart_fields)
{
- err+= add_key_with_algorithm(fptr, part_info,
- current_comment_start);
- err+= add_part_field_list(fptr, part_info->subpart_field_list);
+ err+= add_key_with_algorithm(&str, part_info);
+ err+= add_part_field_list(thd, &str, part_info->subpart_field_list);
}
else
- err+= add_part_key_word(fptr, partition_keywords[PKW_HASH].str);
+ err+= str.append(STRING_WITH_LEN("HASH "));
if (part_info->subpart_expr)
{
- err+= add_begin_parenthesis(fptr);
- err+= add_string_len(fptr, part_info->subpart_func_string,
- part_info->subpart_func_len);
- err+= add_end_parenthesis(fptr);
+ err+= str.append('(');
+ err+= str.append(part_info->subpart_func_string, part_info->subpart_func_len);
+ err+= str.append(')');
}
if ((!part_info->use_default_num_subpartitions) &&
part_info->use_default_subpartitions)
{
- err+= add_string(fptr, "\n");
- err+= add_string(fptr, "SUBPARTITIONS ");
- err+= add_int(fptr, part_info->num_subparts);
+ err+= str.append(STRING_WITH_LEN("\nSUBPARTITIONS "));
+ err+= str.append_ulonglong(part_info->num_subparts);
}
}
tot_num_parts= part_info->partitions.elements;
@@ -2558,8 +2335,7 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
if (!part_info->use_default_partitions)
{
bool first= TRUE;
- err+= add_string(fptr, "\n");
- err+= add_begin_parenthesis(fptr);
+ err+= str.append(STRING_WITH_LEN("\n("));
i= 0;
do
{
@@ -2568,80 +2344,48 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
part_elem->part_state != PART_REORGED_DROPPED)
{
if (!first)
- {
- err+= add_comma(fptr);
- err+= add_string(fptr, "\n");
- err+= add_space(fptr);
- }
+ err+= str.append(STRING_WITH_LEN(",\n "));
first= FALSE;
- err+= add_partition(fptr);
- err+= add_name_string(fptr, part_elem->partition_name);
- err+= add_partition_values(fptr, part_info, part_elem,
+ err+= str.append(STRING_WITH_LEN("PARTITION "));
+ err+= append_identifier(thd, &str, part_elem->partition_name,
+ strlen(part_elem->partition_name));
+ err+= add_partition_values(&str, part_info, part_elem,
create_info, alter_info);
if (!part_info->is_sub_partitioned() ||
part_info->use_default_subpartitions)
{
if (show_partition_options)
- err+= add_partition_options(fptr, part_elem);
+ err+= add_partition_options(&str, part_elem);
}
else
{
- err+= add_string(fptr, "\n");
- err+= add_space(fptr);
- err+= add_begin_parenthesis(fptr);
+ err+= str.append(STRING_WITH_LEN("\n ("));
List_iterator<partition_element> sub_it(part_elem->subpartitions);
j= 0;
do
{
part_elem= sub_it++;
- err+= add_subpartition(fptr);
- err+= add_name_string(fptr, part_elem->partition_name);
+ err+= str.append(STRING_WITH_LEN("SUBPARTITION "));
+ err+= append_identifier(thd, &str, part_elem->partition_name,
+ strlen(part_elem->partition_name));
if (show_partition_options)
- err+= add_partition_options(fptr, part_elem);
+ err+= add_partition_options(&str, part_elem);
if (j != (num_subparts-1))
- {
- err+= add_comma(fptr);
- err+= add_string(fptr, "\n");
- err+= add_space(fptr);
- err+= add_space(fptr);
- }
+ err+= str.append(STRING_WITH_LEN(",\n "));
else
- err+= add_end_parenthesis(fptr);
+ err+= str.append(')');
} while (++j < num_subparts);
}
}
if (i == (tot_num_parts-1))
- err+= add_end_parenthesis(fptr);
+ err+= str.append(')');
} while (++i < tot_num_parts);
}
+ thd->variables.option_bits= save_options;
if (err)
- goto close_file;
- buffer_length= mysql_file_seek(fptr, 0L, MY_SEEK_END, MYF(0));
- if (unlikely(buffer_length == MY_FILEPOS_ERROR))
- goto close_file;
- if (unlikely(mysql_file_seek(fptr, 0L, MY_SEEK_SET, MYF(0))
- == MY_FILEPOS_ERROR))
- goto close_file;
- *buf_length= (uint)buffer_length;
- if (use_sql_alloc)
- buf= (char*) thd->alloc(*buf_length + 1);
- else
- buf= (char*) my_malloc(*buf_length+1, MYF(MY_WME));
- if (!buf)
- goto close_file;
-
- if (unlikely(mysql_file_read(fptr, (uchar*)buf, *buf_length, MYF(MY_FNABP))))
- {
- if (!use_sql_alloc)
- my_free(buf);
- buf= NULL;
- }
- else
- buf[*buf_length]= 0;
-
-close_file:
- mysql_file_close(fptr, MYF(0));
- DBUG_RETURN(buf);
+ DBUG_RETURN(NULL);
+ *buf_length= str.length();
+ DBUG_RETURN(thd->strmake(str.ptr(), str.length()));
}
diff --git a/sql/sql_partition.h b/sql/sql_partition.h
index c2665a8366b..96136790046 100644
--- a/sql/sql_partition.h
+++ b/sql/sql_partition.h
@@ -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 */
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 1bc2321c1ca..d0d253cd911 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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();
}
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 62473e082c3..c16b2ef9844 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -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)
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 18f5f4cac5c..9a9fff8522c 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -471,6 +471,7 @@ public:
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);
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index db708ff613c..222b3182114 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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;
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 56931f47f24..e980a42eef0 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -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()));