[Commits] Rev 4141: Better comments. in file:///home/psergey/dev2/10.0-cp/

Sergey Petrunya psergey at askmonty.org
Mon Mar 31 04:17:00 EEST 2014


At file:///home/psergey/dev2/10.0-cp/

------------------------------------------------------------
revno: 4141
revision-id: psergey at askmonty.org-20140331011658-30haw71pp9b2ceno
parent: sergii at pisem.net-20140329163246-mzfkzyodua370lx5
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 10.0-cp
timestamp: Mon 2014-03-31 05:16:58 +0400
message:
  Better comments.
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2014-03-26 21:25:38 +0000
+++ b/sql/opt_range.cc	2014-03-31 01:16:58 +0000
@@ -3515,6 +3515,9 @@ bool calculate_cond_selectivity_for_tabl
       set_if_bigger(max_quick_key_parts, table->quick_key_parts[keynr]);
   }
 
+  /* 
+    Walk through all keys, keys where range access uses more keyparts go first
+  */
   for (uint quick_key_parts= max_quick_key_parts;
        quick_key_parts; quick_key_parts--)
   {
@@ -3529,6 +3532,16 @@ bool calculate_cond_selectivity_for_tabl
 	                               table_records;
         KEY *key_info= table->key_info + keynr;
         KEY_PART_INFO* key_part= key_info->key_part;
+        /*
+          Suppose, there are range conditions on two keys
+            KEY1 (col1, col2)
+            KEY2 (col3, col2)
+          
+          we don't want to count selectivity of condition on col2 twice.
+          
+          First, find the longest key prefix that's made of columns whose
+          selectivity wasn't already accounted for.
+        */
         for (i= 0; i < used_key_parts; i++, key_part++)
         {
           if (bitmap_is_set(used_fields, key_part->fieldnr-1))
@@ -3537,9 +3550,17 @@ bool calculate_cond_selectivity_for_tabl
         }
         if (i)
         {
+          /* 
+            There is at least 1-column prefix of columns whose selectivity is
+            not yet accounted for
+          */
           table->cond_selectivity*= quick_cond_selectivity;
           if (i != used_key_parts)
 	  {
+            /*
+              Range access got us estimate for #used_key_parts.
+              We need estimate for #(i-1) key parts.
+            */
             double f1= key_info->actual_rec_per_key(i-1);
             double f2= key_info->actual_rec_per_key(i);
             table->cond_selectivity*= f1 / f2;
@@ -3549,7 +3570,7 @@ bool calculate_cond_selectivity_for_tabl
     }
   }
 
-  /* Calculate selectivity of probably highly selective predicates */
+  /* Check if we can improve selectivity estimates by using sampling */
   ulong check_rows=
     MY_MIN(thd->variables.optimizer_selectivity_sampling_limit,
         (ulong) (table_records * SELECTIVITY_SAMPLING_SHARE));



More information about the commits mailing list