summaryrefslogtreecommitdiff
path: root/sql/opt_subselect.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2019-10-15 12:24:23 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2019-10-15 13:20:22 +0200
commit4ba763db77a954e355cdb90a7ef30572e2a4317b (patch)
tree526f83cfc2b3dcd30605b1d61c4cdefd3df0ff88 /sql/opt_subselect.cc
parentc2854c7863aa01895febfb6503f542fce6825bd6 (diff)
downloadmariadb-git-4ba763db77a954e355cdb90a7ef30572e2a4317b.tar.gz
MDEV-13172: Wrong result / SELECT ... WHERE EXISTS ... (with UNIQUE Key)bb-5.5-MDEV-13172
IS NULL or <=> with unique field does not mean unique row, because several NULL possible, so we can not convert to normal join in this case.
Diffstat (limited to 'sql/opt_subselect.cc')
-rw-r--r--sql/opt_subselect.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index cb821325e57..f876129aed7 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -2640,9 +2640,17 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables)
{
do /* For all equalities on all key parts */
{
- /* Check if this is "t.keypart = expr(outer_tables) */
+ /*
+ Check if this is "t.keypart = expr(outer_tables)
+
+ Don't allow variants that can produce duplicates:
+ - Dont allow "ref or null"
+ - the keyuse (that is, the operation) must be null-rejecting,
+ unless the other expression is non-NULLable.
+ */
if (!(keyuse->used_tables & sj_inner_tables) &&
- !(keyuse->optimize & KEY_OPTIMIZE_REF_OR_NULL))
+ !(keyuse->optimize & KEY_OPTIMIZE_REF_OR_NULL) &&
+ (keyuse->null_rejecting || !keyuse->val->maybe_null))
{
bound_parts |= 1 << keyuse->keypart;
}