[Commits] Rev 3377: Fixed calculation of rec_per_key elements for added components of the extended keys. in file:///home/igor/maria/maria-5.3-mwl247/

Igor Babaev igor at askmonty.org
Mon Jan 2 06:47:37 EET 2012


At file:///home/igor/maria/maria-5.3-mwl247/

------------------------------------------------------------
revno: 3377
revision-id: igor at askmonty.org-20120102044736-upxylo1nru6h8f8f
parent: igor at askmonty.org-20111231113620-010z90apx0du8o7c
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-mwl247
timestamp: Sun 2012-01-01 20:47:36 -0800
message:
  Fixed calculation of rec_per_key elements for added components of the extended keys.
  Slightly corrected the implementation of the function ha_innobase::read_time().
  Changed the implementation of handler::keyread_time to make the cost of single key
  index only look-ups dependent on the key entry length.
  Corrected the index of the last possible components of an extended key in the
  function best_access_path().
-------------- next part --------------
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-12-11 16:39:33 +0000
+++ b/sql/handler.cc	2012-01-02 04:47:36 +0000
@@ -2146,11 +2146,12 @@
     performs a random seek, thus the cost is proportional to the number of
     blocks read. This model does not take into account clustered indexes -
     engines that support that (e.g. InnoDB) may want to overwrite this method.
+    The model counts in the time to read index entries from cache.
   */
-  double keys_per_block= (stats.block_size/2.0/
-                          (table->key_info[index].key_length +
-                           ref_length) + 1);
-  return (rows + keys_per_block - 1)/ keys_per_block;
+  ulong len= table->key_info[index].key_length + ref_length;
+  double keys_per_block= (stats.block_size/2.0/len+1);
+  return (rows + keys_per_block-1)/ keys_per_block +
+         len*rows/(stats.block_size+1)/TIME_FOR_COMPARE ;
 }
 
 void **handler::ha_data(THD *thd) const

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-12-31 11:36:20 +0000
+++ b/sql/sql_select.cc	2012-01-02 04:47:36 +0000
@@ -5193,7 +5193,8 @@
             }
             else
             {
-              if (!(records=keyinfo->rec_per_key[keyinfo->key_parts-1]))
+              uint key_parts= table->actual_n_key_parts(keyinfo);
+              if (!(records=keyinfo->rec_per_key[key_parts-1]))
               {                                   /* Prefer longer keys */
                 records=
                   ((double) s->records / (double) rec *

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2011-12-31 11:36:20 +0000
+++ b/sql/table.cc	2012-01-02 04:47:36 +0000
@@ -5580,7 +5580,7 @@
   @return number of considered key components
 */ 
 
-inline uint st_table::actual_n_key_parts(KEY *keyinfo)
+uint st_table::actual_n_key_parts(KEY *keyinfo)
 {
   return optimizer_flag(in_use, OPTIMIZER_SWITCH_EXTENDED_KEYS) ?
            keyinfo->ext_key_parts : keyinfo->key_parts;

=== modified file 'storage/xtradb/handler/ha_innodb.cc'
--- a/storage/xtradb/handler/ha_innodb.cc	2011-12-31 11:36:20 +0000
+++ b/storage/xtradb/handler/ha_innodb.cc	2012-01-02 04:47:36 +0000
@@ -8230,11 +8230,6 @@
 		return(handler::read_time(index, ranges, rows));
 	}
 
-	if (rows <= 2) {
-
-		return((double) rows);
-	}
-
 	/* Assume that the read time is proportional to the scan time for all
 	rows + at most one seek per range. */
 
@@ -8679,30 +8674,37 @@
 			}
 
                         KEY *key_info= table->key_info+i; 
-                        key_part_map ext_key_part_map= key_info->ext_key_part_map;                               
+                        key_part_map ext_key_part_map=
+                                             key_info->ext_key_part_map;                               
 
                         if (key_info->key_parts != key_info->ext_key_parts) {
 
-
                                 KEY *pk_key_info= key_info+
                                                   table->s->primary_key;
-                                uint k= key_info->key_parts;
-                                                              
-                                for (j = 0; j < pk_key_info->key_parts; j++) {
+                                uint k = key_info->key_parts;
+                                ha_rows k_rec_per_key = rec_per_key;
+                                uint pk_parts = pk_key_info->key_parts;
+                          
+		                index= innobase_get_index(
+                                        table->s->primary_key);
+                                    
+                                for (j = 0; j < pk_parts; j++) {
  
 				         if (ext_key_part_map & 1<<j) {
 
-		                                index = innobase_get_index(
-                                                         table->s->primary_key);
                                                 rec_per_key =
 						innodb_rec_per_key(index,
                                                         j, stats.records);
                                
-                        
 				                if (rec_per_key == 0) {
 					                rec_per_key = 1;
 				                }
-
+                                                else if (rec_per_key > 1) {
+                                                        rec_per_key =
+                                                        k_rec_per_key *
+						        (double)rec_per_key /
+							n_rows;
+						}
                                                 
 				                key_info->rec_per_key[k++]=
 				                rec_per_key >= ~(ulong) 0 ?



More information about the commits mailing list