diff options
author | Igor Babaev <igor@askmonty.org> | 2013-04-17 16:15:22 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2013-04-17 16:15:22 -0700 |
commit | ac8333e46d63c87178e1844b95d89c87439e03e3 (patch) | |
tree | 2ae581459f8a20bf4f94498623e1a46d184fad8a /sql/sql_select.cc | |
parent | 2e54ad03adc932846a3252f53092cafbddbe646e (diff) | |
download | mariadb-git-ac8333e46d63c87178e1844b95d89c87439e03e3.tar.gz |
Fixed a typo/bug that could lead to wrong selectivity numbers for
tables retrieved by range scans.
Added comments forgotten in the previous patch.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index be8ff20eb48..cc4b139fb2f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6905,6 +6905,18 @@ double JOIN::get_examined_rows() } +/** + @brief + Get the selectivity of equalities between columns when joining a table + + @param join The optimized join + @param idx The number of tables in the evaluated partual join + @param s The table to be joined for evaluation + @param rem_tables The bitmap of tables to be joined later + @param keyparts The number of key parts to used when joining s + @param ref_keyuse_steps Array of references to keyuses employed to join s +*/ + static double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, table_map rem_tables, uint keyparts, @@ -7015,6 +7027,19 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, return sel; } + +/** + @brief + 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 + + @retval + selectivity of the conditions imposed on the rows of s +*/ + static double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, table_map rem_tables) @@ -7034,7 +7059,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, { if (pos->key == 0 && table_records > 0) { - sel*= table->quick_rows[s->quick->index]/table_records; + sel/= table->quick_rows[s->quick->index]/table_records; } } else if (pos->key != 0) @@ -7085,6 +7110,11 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, } while (keyuse->table == table && keyuse->key == key); } + /* + If the field f from the table is equal to a field from one the + earlier joined tables then the selectivity of the range conditions + over the field f must be discounted. + */ for (Field **f_ptr=table->field ; (field= *f_ptr) ; f_ptr++) { if (!bitmap_is_set(read_set, field->field_index) || @@ -12275,9 +12305,9 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, @endcode Thus, applying equalities from the where condition we basically can get more freedom in performing join operations. - Althogh we don't use this property now, it probably makes sense to use + Although we don't use this property now, it probably makes sense to use it in the future. - @param thd Thread handler + @param thd Thread handler @param cond condition to build the multiple equalities for @param inherited path to all inherited multiple equality items @param join_list list of join tables to which the condition @@ -12286,6 +12316,7 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, for on expressions @param[out] cond_equal_ref pointer to the structure to place built equalities in + @param link_equal_items equal fields are to be linked @return pointer to the transformed condition containing multiple equalities |