From: Mattias Jonsson Date: October 28 2010 3:21pm Subject: bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:3545) Bug#56438 List-Archive: http://lists.mysql.com/commits/122220 X-Bug: 56438 Message-Id: <201010281521.o9SD7QOG015515@acsinet15.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2330941463613081467==" --===============2330941463613081467== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #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); --===============2330941463613081467== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/mattias.jonsson@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: mattias.jonsson@stripped\ # kni4khxmyhynca0n # target_branch: file:///Users/mattiasj/mysql-bzr/b56438-51-bt/ # testament_sha1: 5547898936c9cd1c11964c2c06ee7540f30c419a # timestamp: 2010-10-28 17:21:41 +0200 # base_revision_id: li-bing.song@stripped\ # 59ljye6ii4t7m2za # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWakampsABe5/gGJUAFhZ//// f//eKr////pgC+t97HHu+L54l33XaI2Xvp4afdu933333uDqSzbt3PW97kYSSQKn5KeMVP1PVP1R +I0nlJmUNNNDEPUD1ADQ0aDaglEaTCaZEaamk9J5SPU0PSNMgAAAAAA0GmgRNJpTxJ6majxR6TQ0 AAGRoAAAAAkRSYhNTwp4p4mKMmho02p6QAAAMQBp6QEUkmmTRNlMmGp6EyaMSTwmoAGgAA0AAIpC BNMgAgUz0p5T0no1DamIyD1NqAAANCOBtjJy23+2r32v87rcMG0yRM1fxtlyZ4RgaWMPt0SnS35/ Wnd6Xmrkh3HUeLPcs8fsi2vJxNsXDnZZOZjf1NJvVw2eHj2oXTdTDMQEggBCjDLmaxt1nZ9S1Mg5 8JUTYRhWqn5zwx0eFUKH3/7psok4RqgE46Zo5fAG6PN4bg4zyxwo+yMaG22NtpJtFo+4LPl/lN7R tuSWWG9KhymS4AOWu1rTVreIAsRSjqsPeZZbzQ0hbX4XtYrGIhnpidzeYvUzS7IgHrPNbd5OiNVJ 0bN7wa3FbWew1pr6RFd7AUS4ZtVLTtC8CrkbpOOa/gXTxH8jjrKt0ZClXFVSP9QfFfHeYVdvgGKh d0HOqyir/HooLjw2MKWM1eq4tNC2rNl1xg4pRjKHixEmTQ/519IkxS2TTEI4W4G7NnZyGdGD7em0 b4cb4KQkbIPSA3leU0OwwwZ0Xgol4sZlG1IkhRdpe4GsEQMJFGuZ+R2noqRu0aCAZBBwO/vQtTHt zetndustBrZQDQUem0jGmesOdrYYYeIpuTIvm2YEOzBIhC5w0UbQ3cEOnhV5i0NnU0OWtJPZLBLB VVzxMWXkZBDCsb8kpMMmJSoENr0nTcQmhpsqSaZIxdeSgEwtCbSvZMmLPVTTTlTWXSChw4GhFChC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