diff options
author | Varun Gupta <varunraiko1803@gmail.com> | 2018-10-31 23:30:34 +0530 |
---|---|---|
committer | Varun Gupta <varunraiko1803@gmail.com> | 2018-11-01 13:20:26 +0530 |
commit | 38b3e52c3c40b35339b1d18c09053be416a93420 (patch) | |
tree | 1775d0c58ece9eeefa2f0d6993c8e86bb21d0568 /sql/opt_range.cc | |
parent | c4c738e1ef983a0a4353957cf5d488a3f2cb0a58 (diff) | |
download | mariadb-git-38b3e52c3c40b35339b1d18c09053be416a93420.tar.gz |
MDEV-16695: Estimate for rows of derived tables is very high when we are using index_merge union
For index merge union[or sort union], the estimates are not taken into account while calculating the selectivity of
a condition. So instead of showing the estimates of the index merge union[or sort union], it shows estimates equal to
all the records of the table.
The fix for the issue is to include the selectivity of index merge
union[or sort union] while calculating the selectivity of a condition.
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r-- | sql/opt_range.cc | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 0fd2cd267fc..3bcaa72e32f 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3725,6 +3725,12 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond) } + if (quick && (quick->get_type() == QUICK_SELECT_I::QS_TYPE_ROR_UNION || + quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)) + { + table->cond_selectivity*= (quick->records/table_records); + } + bitmap_union(used_fields, &handled_columns); /* Check if we can improve selectivity estimates by using sampling */ |