[Commits] Rev 4143: More comments in condition selectivity code. in file:///home/psergey/dev2/10.0/

Sergey Petrunya psergey at askmonty.org
Mon Mar 31 18:51:49 EEST 2014


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

------------------------------------------------------------
revno: 4143
revision-id: psergey at askmonty.org-20140331155148-174h1ee2c4vbjbq5
parent: psergey at askmonty.org-20140331042440-llucqhu68vcvua8d
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 10.0
timestamp: Mon 2014-03-31 10:51:48 -0500
message:
  More comments in condition selectivity code.
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2014-03-26 21:25:38 +0000
+++ b/sql/sql_select.cc	2014-03-31 15:51:48 +0000
@@ -5557,7 +5557,20 @@ void set_position(JOIN *join,uint idx,JO
 }
 
 
-/* Estimate of the number matching candidates in the joined table */
+/*
+  Estimate how many records we will get if we read just this table and apply
+  a part of WHERE that can be checked for it.
+
+  @detail
+  Estimate how many records we will get if we
+   - read the given table with its "independent" access method (either quick 
+     select or full table/index scan),
+   - apply the part of WHERE that refers only to this table.
+
+  @seealso
+    table_cond_selectivity() produces selectivity of condition that is checked
+    after joining rows from this table to rows from preceding tables.
+*/
 
 inline
 double matching_candidates_in_table(JOIN_TAB *s, bool with_found_constraint,
@@ -7236,14 +7249,25 @@ double table_multi_eq_cond_selectivity(J
 
 /**
   @brief
-  Get the selectivity of conditions when joining a table
+    Get the selectivity of conditions when joining a table
 
   @param join       The optimized join
   @param s          The table to be joined for evaluation
   @param rem_tables The bitmap of tables to be joined later
 
+  @detail
+    Get selectivity of conditions that can be applied when joining this table
+    with previous.
+
+    For quick selects and full table scans, selectivity of COND(this_table)
+    is accounted for in matching_candidates_in_table(). Here, we only count
+    selectivity of COND(this_table, previous_tables). 
+
+    For other access methods, we need to calculate selectivity of the whole
+    condition, "COND(this_table) AND COND(this_table, previous_tables)".
+
   @retval
-  selectivity of the conditions imposed on the rows of s
+    selectivity of the conditions imposed on the rows of s
 */
 
 static
@@ -7265,12 +7289,26 @@ double table_cond_selectivity(JOIN *join
   {
     if (pos->key == 0 && table_records > 0)
     {
+      /*
+        We're using a quick select. the part of WHERE that was used to
+        construct the quick select will not be selective (all rows we read 
+        will match). Remove selectivity factor of this quick select from join's
+        selectivity.
+      */
       sel/= table->quick_rows[s->quick->index]/table_records;
     }
   }
   else if (pos->key != 0)
   {
-    /* A ref/ access or hash join is used to join table */
+    /* 
+      A ref/ access or hash join is used to join table
+
+      It could have some parts with "t.key=const". Ref access guarantees that
+      we will only get records where the condition holds, so we should remove
+      its its selectivity from the condition selectivity.
+      
+      (TODO: more details about the "t.key=othertable.col" case)
+    */
     KEYUSE *keyuse= pos->key;
     KEYUSE *prev_ref_keyuse= keyuse;
     uint key= keyuse->key;
@@ -7317,6 +7355,11 @@ double table_cond_selectivity(JOIN *join
   }
   else
   {
+    /*
+      We get here when the table uses full table scan.
+      Selectivity of COND(table) is already accounted for in
+      matching_candidates_in_table().
+    */
     sel= 1;
   }
     



More information about the commits mailing list