summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2021-01-06 10:53:00 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2021-01-06 10:53:00 +0100
commit02e7bff882c5169ba3e1ce7e9a93d4c28fe3afd1 (patch)
tree4a6a8d578fedb4c2b1f437ab39c2d7430ad95163 /sql/opt_range.cc
parent5f10870c8a8c2448bfc26d990110390d48000b84 (diff)
parent478b83032b170b2ae030fa77fe4bed60a7910472 (diff)
downloadmariadb-git-02e7bff882c5169ba3e1ce7e9a93d4c28fe3afd1.tar.gz
Merge commit '10.4' into 10.5
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index cb5a0604733..f146fc25126 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -7801,6 +7801,30 @@ SEL_TREE *Item_func_in::get_func_mm_tree(RANGE_OPT_PARAM *param,
if (array->count > NOT_IN_IGNORE_THRESHOLD || !value_item)
DBUG_RETURN(0);
+ /*
+ If this is "unique_key NOT IN (...)", do not consider it sargable (for
+ any index, not just the unique one). The logic is as follows:
+ - if there are only a few constants, this condition is not selective
+ (unless the table is also very small in which case we won't gain
+ anything)
+ - If there are a lot of constants, the overhead of building and
+ processing enormous range list is not worth it.
+ */
+ if (param->using_real_indexes)
+ {
+ key_map::Iterator it(field->key_start);
+ uint key_no;
+ while ((key_no= it++) != key_map::Iterator::BITMAP_END)
+ {
+ KEY *key_info= &field->table->key_info[key_no];
+ if (key_info->user_defined_key_parts == 1 &&
+ (key_info->flags & HA_NOSAME))
+ {
+ DBUG_RETURN(0);
+ }
+ }
+ }
+
/* Get a SEL_TREE for "(-inf|NULL) < X < c_0" interval. */
uint i=0;
do