summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2019-08-15 12:57:21 +0300
committerSergei Petrunia <psergey@askmonty.org>2019-08-15 12:57:21 +0300
commit1c75ad6eed744672fdce77b0752801b67edb69f8 (patch)
tree77b4c8a41e0a3fc00e5b4d9e159410fac17878a2 /sql/sql_select.cc
parent588e67956af5c21191189f669f11f083e8ae35f7 (diff)
downloadmariadb-git-1c75ad6eed744672fdce77b0752801b67edb69f8.tar.gz
MDEV-19834 Selectivity of an equality condition discounted twice
When discounting selectivity of ref access, don't discount the selectivity we've already discounted for range access. The 10.1 version of the fix. Will need to adjust condition filtering test results in 10.4
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index fb8e4755b1d..29fc3f80ed0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -7618,6 +7618,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
KEYUSE *keyuse= pos->key;
KEYUSE *prev_ref_keyuse= keyuse;
uint key= keyuse->key;
+ bool used_range_selectivity= false;
/*
Check if we have a prefix of key=const that matches a quick select.
@@ -7643,6 +7644,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
keyparts++;
}
sel /= (double)table->quick_rows[key] / (double) table->stat_records();
+ used_range_selectivity= true;
}
}
@@ -7678,13 +7680,14 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
if (keyparts > keyuse->keypart)
{
/* Ok this is the keyuse that will be used for ref access */
- uint fldno;
- if (is_hash_join_key_no(key))
- fldno= keyuse->keypart;
- else
- fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1;
- if (keyuse->val->const_item())
+ if (!used_range_selectivity && keyuse->val->const_item())
{
+ uint fldno;
+ if (is_hash_join_key_no(key))
+ fldno= keyuse->keypart;
+ else
+ fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1;
+
if (table->field[fldno]->cond_selectivity > 0)
{
sel /= table->field[fldno]->cond_selectivity;