summaryrefslogtreecommitdiff
path: root/sql/partition_info.cc
diff options
context:
space:
mode:
authormikael/pappa@dator5.(none) <>2006-10-16 15:40:40 -0400
committermikael/pappa@dator5.(none) <>2006-10-16 15:40:40 -0400
commit4a7cd3a1cb103854af8b38a47a966d2b06d68045 (patch)
tree3635695d4cd8a873ae2eac0d07692901393eedfc /sql/partition_info.cc
parente6be42e1c97bcb29c0c0ab5cc58185ee4293f86b (diff)
parent1cdf82e012148370a721d9c4ac5c3cc9bcba00ba (diff)
downloadmariadb-git-4a7cd3a1cb103854af8b38a47a966d2b06d68045.tar.gz
Merge dator5.(none):/home/pappa/clean-mysql-5.1
into dator5.(none):/home/pappa/bug18198
Diffstat (limited to 'sql/partition_info.cc')
-rw-r--r--sql/partition_info.cc201
1 files changed, 188 insertions, 13 deletions
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index b3c7c1b80e7..a20fca9404b 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -693,6 +693,7 @@ end:
file A reference to a handler of the table
info Create info
engine_type Return value for used engine in partitions
+ check_partition_function Should we check the partition function
RETURN VALUE
TRUE Error, something went wrong
@@ -707,26 +708,33 @@ end:
*/
bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
- handler *file, HA_CREATE_INFO *info)
+ handler *file, HA_CREATE_INFO *info,
+ bool check_partition_function)
{
handlerton **engine_array= NULL;
uint part_count= 0;
uint i, tot_partitions;
bool result= TRUE;
char *same_name;
- bool part_expression_ok= TRUE;
DBUG_ENTER("partition_info::check_partition_info");
- if (part_type != HASH_PARTITION || !list_of_part_fields)
- part_expr->walk(&Item::check_partition_func_processor, 0,
- (byte*)(&part_expression_ok));
- if (is_sub_partitioned() && !list_of_subpart_fields)
- subpart_expr->walk(&Item::check_partition_func_processor, 0,
- (byte*)(&part_expression_ok));
- if (!part_expression_ok)
+ if (check_partition_function)
{
- my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
- goto end;
+ int err= 0;
+
+ if (part_type != HASH_PARTITION || !list_of_part_fields)
+ {
+ err= part_expr->walk(&Item::check_partition_func_processor, 0,
+ NULL);
+ if (!err && is_sub_partitioned() && !list_of_subpart_fields)
+ err= subpart_expr->walk(&Item::check_partition_func_processor, 0,
+ NULL);
+ }
+ if (err)
+ {
+ my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
+ goto end;
+ }
}
if (unlikely(!is_sub_partitioned() &&
!(use_default_subpartitions && use_default_no_subpartitions)))
@@ -828,11 +836,12 @@ end:
/*
Print error for no partition found
+
SYNOPSIS
print_no_partition_found()
table Table object
+
RETURN VALUES
- NONE
*/
void partition_info::print_no_partition_found(TABLE *table)
@@ -844,10 +853,176 @@ void partition_info::print_no_partition_found(TABLE *table)
if (part_expr->null_value)
buf_ptr= (char*)"NULL";
else
- longlong2str(part_expr->val_int(), buf,
+ longlong2str(err_value, buf,
part_expr->unsigned_flag ? 10 : -10);
my_error(ER_NO_PARTITION_FOR_GIVEN_VALUE, MYF(0), buf_ptr);
dbug_tmp_restore_column_map(table->read_set, old_map);
}
+/*
+ Set up buffers and arrays for fields requiring preparation
+ SYNOPSIS
+ set_up_charset_field_preps()
+
+ RETURN VALUES
+ TRUE Memory Allocation error
+ FALSE Success
+ DESCRIPTION
+ Set up arrays and buffers for fields that require special care for
+ calculation of partition id. This is used for string fields with
+ variable length or string fields with fixed length that isn't using
+ the binary collation.
+*/
+
+bool partition_info::set_up_charset_field_preps()
+{
+ Field *field, **ptr;
+ char *field_buf;
+ char **char_ptrs;
+ unsigned i;
+ bool found;
+ size_t size;
+ uint tot_fields= 0;
+ uint tot_part_fields= 0;
+ uint tot_subpart_fields= 0;
+ DBUG_ENTER("set_up_charset_field_preps");
+
+ if (!(part_type == HASH_PARTITION &&
+ list_of_part_fields) &&
+ check_part_func_fields(part_field_array, FALSE))
+ {
+ ptr= part_field_array;
+ /* Set up arrays and buffers for those fields */
+ i= 0;
+ while ((field= *(ptr++)))
+ {
+ if (field_is_partition_charset(field))
+ {
+ tot_part_fields++;
+ tot_fields++;
+ }
+ }
+ size= tot_part_fields * sizeof(char*);
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ part_field_buffers= char_ptrs;
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ restore_part_field_ptrs= char_ptrs;
+ size= (tot_part_fields + 1) * sizeof(Field*);
+ if (!(char_ptrs= (char**)sql_alloc(size)))
+ goto error;
+ part_charset_field_array= (Field**)char_ptrs;
+ ptr= part_field_array;
+ i= 0;
+ while ((field= *(ptr++)))
+ {
+ if (field_is_partition_charset(field))
+ {
+ CHARSET_INFO *cs= ((Field_str*)field)->charset();
+ size= field->pack_length();
+ if (!(field_buf= sql_calloc(size)))
+ goto error;
+ part_charset_field_array[i]= field;
+ part_field_buffers[i++]= field_buf;
+ }
+ }
+ part_charset_field_array[i]= NULL;
+ }
+ if (is_sub_partitioned() && list_of_subpart_fields &&
+ check_part_func_fields(subpart_field_array, FALSE))
+ {
+ /* Set up arrays and buffers for those fields */
+ ptr= subpart_field_array;
+ while ((field= *(ptr++)))
+ {
+ if (field_is_partition_charset(field))
+ tot_subpart_fields++;
+ }
+ size= tot_subpart_fields * sizeof(char*);
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ subpart_field_buffers= char_ptrs;
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ restore_subpart_field_ptrs= char_ptrs;
+ size= (tot_subpart_fields + 1) * sizeof(Field*);
+ if (!(char_ptrs= (char**)sql_alloc(size)))
+ goto error;
+ subpart_charset_field_array= (Field**)char_ptrs;
+ i= 0;
+ while ((field= *(ptr++)))
+ {
+ unsigned j= 0;
+ Field *part_field;
+ CHARSET_INFO *cs;
+
+ if (!field_is_partition_charset(field))
+ continue;
+ cs= ((Field_str*)field)->charset();
+ size= field->pack_length();
+ found= FALSE;
+ for (j= 0; j < tot_part_fields; j++)
+ {
+ if (field == part_charset_field_array[i])
+ found= TRUE;
+ }
+ if (!found)
+ {
+ tot_fields++;
+ if (!(field_buf= sql_calloc(size)))
+ goto error;
+ }
+ subpart_field_buffers[i++]= field_buf;
+ }
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ restore_subpart_field_ptrs= char_ptrs;
+ }
+ if (tot_fields)
+ {
+ Field *part_field, *subpart_field;
+ uint j,k,l;
+
+ size= tot_fields*sizeof(char**);
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ full_part_field_buffers= char_ptrs;
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ restore_full_part_field_ptrs= char_ptrs;
+ size= (tot_fields + 1) * sizeof(char**);
+ if (!(char_ptrs= (char**)sql_calloc(size)))
+ goto error;
+ full_part_charset_field_array= (Field**)char_ptrs;
+ for (i= 0; i < tot_part_fields; i++)
+ {
+ full_part_charset_field_array[i]= part_charset_field_array[i];
+ full_part_field_buffers[i]= part_field_buffers[i];
+ }
+ k= tot_part_fields;
+ l= 0;
+ for (i= 0; i < tot_subpart_fields; i++)
+ {
+ field= subpart_charset_field_array[i];
+ found= FALSE;
+ for (j= 0; j < tot_part_fields; j++)
+ {
+ if (field == part_charset_field_array[i])
+ found= TRUE;
+ }
+ if (!found)
+ {
+ full_part_charset_field_array[l]= subpart_charset_field_array[k];
+ full_part_field_buffers[l]= subpart_field_buffers[k];
+ k++; l++;
+ }
+ }
+ full_part_charset_field_array[tot_fields]= NULL;
+ }
+ DBUG_RETURN(FALSE);
+error:
+ mem_alloc_error(size);
+ DBUG_RETURN(TRUE);
+}
#endif /* WITH_PARTITION_STORAGE_ENGINE */