summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-05-05 20:33:10 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-05-05 20:33:10 +0300
commit2c3c851d2cba73825f81cd06220138b15c17ae4d (patch)
tree4130cf52868c41beb3c242ad229031cca73d7e1c /sql/sql_select.cc
parent474290540a829edcc6a74be8c354053f330bf5de (diff)
parent8648b9bed86e9f52c027daec760d6ab5ce52e889 (diff)
downloadmariadb-git-2c3c851d2cba73825f81cd06220138b15c17ae4d.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a64eb5b327d..b8173ab036c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10678,6 +10678,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
uchar *key_buff=j->ref.key_buff, *null_ref_key= 0;
uint null_ref_part= NO_REF_PART;
bool keyuse_uses_no_tables= TRUE;
+ uint not_null_keyparts= 0;
if (ftkey)
{
j->ref.items[0]=((Item_func*)(keyuse->val))->key_item();
@@ -10707,6 +10708,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
j->ref.items[i]=keyuse->val; // Save for cond removal
j->ref.cond_guards[i]= keyuse->cond_guard;
+ if (!keyuse->val->maybe_null || keyuse->null_rejecting)
+ not_null_keyparts++;
/*
Set ref.null_rejecting to true only if we are going to inject a
"keyuse->val IS NOT NULL" predicate.
@@ -10766,12 +10769,18 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
ulong key_flags= j->table->actual_key_flags(keyinfo);
if (j->type == JT_CONST)
j->table->const_table= 1;
- else if (!((keyparts == keyinfo->user_defined_key_parts &&
- ((key_flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME)) ||
- (keyparts > keyinfo->user_defined_key_parts && // true only for extended keys
- MY_TEST(key_flags & HA_EXT_NOSAME) &&
- keyparts == keyinfo->ext_key_parts)) ||
- null_ref_key)
+ else if (!((keyparts == keyinfo->user_defined_key_parts &&
+ (
+ (key_flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME ||
+ /* Unique key and all keyparts are NULL rejecting */
+ ((key_flags & HA_NOSAME) && keyparts == not_null_keyparts)
+ )) ||
+ /* true only for extended keys */
+ (keyparts > keyinfo->user_defined_key_parts &&
+ MY_TEST(key_flags & HA_EXT_NOSAME) &&
+ keyparts == keyinfo->ext_key_parts)
+ ) ||
+ null_ref_key)
{
/* Must read with repeat */
j->type= null_ref_key ? JT_REF_OR_NULL : JT_REF;