#At file:///Users/mattiasj/mysql-bzr/b56438-51-bt/ based on revid:li-bing.song@stripped
3545 Mattias Jonsson 2010-10-28
Bug#56438: Make it possible for handler to affect the hash value for partition
This is a necessary fix to the partitioning to enable handlers to take care of
the hash value calculation. This is a must for the NDB engine. Fix should have been done
already on 5.1 but this wasn't done for some reason.
@ sql/ha_partition.cc
Moved calculate_key_value from sql_partition.cc to here as
ha_partition::calculate_key_hash_value.
@ sql/ha_partition.h
Extended set_part_info and added calculate_key_hash_value
@ sql/handler.h
Extended set_part_info and added calculate_key_hash_value
@ sql/partition_info.h
Added a reference to the table instance.
@ sql/sql_partition.cc
Using the handlers calculate_key_hash_value (the old calculate_key_value
was moved to ha_partition.cc) and setting the table reference on part_info
modified:
sql/ha_partition.cc
sql/ha_partition.h
sql/handler.h
sql/partition_info.h
sql/sql_partition.cc
=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc 2010-10-01 13:41:27 +0000
+++ b/sql/ha_partition.cc 2010-10-28 15:20:45 +0000
@@ -6156,6 +6156,31 @@ uint8 ha_partition::table_cache_type()
}
+/**
+ Calculate hash value for KEY partitioning using an array of fields.
+
+ @param field_array An array of the fields in KEY partitioning
+
+ @return hash_value calculated
+
+ @note Uses the hash function on the character set of the field.
+ Integer and floating point fields use the binary character set by default.
+*/
+
+uint32 ha_partition::calculate_key_hash_value(Field **field_array)
+{
+ ulong nr1= 1;
+ ulong nr2= 4;
+
+ do
+ {
+ Field *field= *field_array;
+ field->hash(&nr1, &nr2);
+ } while (*(++field_array));
+ return (uint32) nr1;
+}
+
+
/****************************************************************************
MODULE print messages
****************************************************************************/
=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h 2010-10-01 11:39:49 +0000
+++ b/sql/ha_partition.h 2010-10-28 15:20:45 +0000
@@ -187,7 +187,7 @@ private:
enum_monotonicity_info m_part_func_monotonicity_info;
public:
handler *clone(MEM_ROOT *mem_root);
- virtual void set_part_info(partition_info *part_info)
+ virtual void set_part_info(partition_info *part_info, bool early)
{
m_part_info= part_info;
m_is_sub_partitioned= part_info->is_sub_partitioned();
@@ -610,6 +610,9 @@ public:
virtual uint8 table_cache_type();
virtual ha_rows records();
+ /* Calculate hash value for PARTITION BY KEY tables. */
+ uint32 calculate_key_hash_value(Field **field_array);
+
/*
-------------------------------------------------------------------------
MODULE print messages
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2010-07-09 13:00:33 +0000
+++ b/sql/handler.h 2010-10-28 15:20:45 +0000
@@ -1479,6 +1479,8 @@ public:
virtual int info(uint)=0; // see my_base.h for full description
virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info,
uint part_id);
+ virtual uint32 calculate_key_hash_value(Field **field_array)
+ { DBUG_ASSERT(0); return 0; }
virtual int extra(enum ha_extra_function operation)
{ return 0; }
virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
@@ -1593,7 +1595,7 @@ public:
*no_parts= 0;
return 0;
}
- virtual void set_part_info(partition_info *part_info) {return;}
+ virtual void set_part_info(partition_info *part_info, bool early) {return;}
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h 2009-09-02 15:42:08 +0000
+++ b/sql/partition_info.h 2010-10-28 15:20:45 +0000
@@ -154,6 +154,8 @@ public:
partition_element *curr_part_elem;
partition_element *current_partition;
+
+ TABLE *table;
/*
These key_map's are used for Partitioning to enable quick decisions
on whether we can derive more information about which partition to
=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc 2010-10-20 18:21:40 +0000
+++ b/sql/sql_partition.cc 2010-10-28 15:20:45 +0000
@@ -1745,6 +1745,7 @@ bool fix_partition_func(THD *thd, TABLE
set_up_partition_key_maps(table, part_info);
set_up_partition_func_pointers(part_info);
set_up_range_analysis_info(part_info);
+ table->file->set_part_info(part_info, FALSE);
result= FALSE;
end:
thd->mark_used_columns= save_mark_used_columns;
@@ -2321,42 +2322,13 @@ static inline int part_val_int(Item *ite
We have a set of support functions for these 14 variants. There are 4
variants of hash functions and there is a function for each. The KEY
- partitioning uses the function calculate_key_value to calculate the hash
+ partitioning uses the function calculate_key_hash_value to calculate the hash
value based on an array of fields. The linear hash variants uses the
method get_part_id_from_linear_hash to get the partition id using the
hash value and some parameters calculated from the number of partitions.
*/
/*
- Calculate hash value for KEY partitioning using an array of fields.
-
- SYNOPSIS
- calculate_key_value()
- field_array An array of the fields in KEY partitioning
-
- RETURN VALUE
- hash_value calculated
-
- DESCRIPTION
- Uses the hash function on the character set of the field. Integer and
- floating point fields use the binary character set by default.
-*/
-
-static uint32 calculate_key_value(Field **field_array)
-{
- ulong nr1= 1;
- ulong nr2= 4;
-
- do
- {
- Field *field= *field_array;
- field->hash(&nr1, &nr2);
- } while (*(++field_array));
- return (uint32) nr1;
-}
-
-
-/*
A simple support function to calculate part_id given local part and
sub part.
@@ -2443,25 +2415,25 @@ static int get_part_id_linear_hash(parti
}
-/*
+/**
Calculate part_id for (SUB)PARTITION BY KEY
- SYNOPSIS
- get_part_id_key()
- field_array Array of fields for PARTTION KEY
- no_parts Number of KEY partitions
+ @param file Handler to storage engine
+ @param field_array Array of fields for PARTTION KEY
+ @param no_parts Number of KEY partitions
+ @param func_value[out] Returns calculated hash value
- RETURN VALUE
- Calculated partition id
+ @return Calculated partition id
*/
inline
-static uint32 get_part_id_key(Field **field_array,
+static uint32 get_part_id_key(handler *file,
+ Field **field_array,
uint no_parts,
longlong *func_value)
{
DBUG_ENTER("get_part_id_key");
- *func_value= calculate_key_value(field_array);
+ *func_value= file->calculate_key_hash_value(field_array);
DBUG_RETURN((uint32) (*func_value % no_parts));
}
@@ -2488,7 +2460,7 @@ static uint32 get_part_id_linear_key(par
{
DBUG_ENTER("get_partition_id_linear_key");
- *func_value= calculate_key_value(field_array);
+ *func_value= part_info->table->file->calculate_key_hash_value(field_array);
DBUG_RETURN(get_part_id_from_linear_hash(*func_value,
part_info->linear_hash_mask,
no_parts));
@@ -3066,7 +3038,8 @@ int get_partition_id_key_nosub(partition
uint32 *part_id,
longlong *func_value)
{
- *part_id= get_part_id_key(part_info->part_field_array,
+ *part_id= get_part_id_key(part_info->table->file,
+ part_info->part_field_array,
part_info->no_parts, func_value);
return 0;
}
@@ -3160,7 +3133,8 @@ int get_partition_id_range_sub_key(parti
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_key(part_info->subpart_field_array,
+ sub_part_id= get_part_id_key(part_info->table->file,
+ part_info->subpart_field_array,
no_subparts, &local_func_value);
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
@@ -3266,7 +3240,8 @@ int get_partition_id_list_sub_key(partit
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_key(part_info->subpart_field_array,
+ sub_part_id= get_part_id_key(part_info->table->file,
+ part_info->subpart_field_array,
no_subparts, &local_func_value);
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
@@ -3344,7 +3319,8 @@ int get_partition_id_key_sub(partition_i
uint32 *part_id)
{
longlong func_value;
- *part_id= get_part_id_key(part_info->subpart_field_array,
+ *part_id= get_part_id_key(part_info->table->file,
+ part_info->subpart_field_array,
part_info->no_subparts, &func_value);
return FALSE;
}
@@ -3991,7 +3967,8 @@ bool mysql_unpack_partition(THD *thd,
}
}
table->part_info= part_info;
- table->file->set_part_info(part_info);
+ part_info->table= table;
+ table->file->set_part_info(part_info, TRUE);
if (!part_info->default_engine_type)
part_info->default_engine_type= default_db_type;
DBUG_ASSERT(part_info->default_engine_type == default_db_type);
Attachment: [text/bzr-bundle] bzr/mattias.jonsson@oracle.com-20101028152045-kni4khxmyhynca0n.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:3545) Bug#56438 | Mattias Jonsson | 28 Oct |