summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/group_by.result38
-rw-r--r--mysql-test/t/group_by.test26
-rw-r--r--sql/sql_select.cc2
3 files changed, 65 insertions, 1 deletions
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index 7f32643b727..07773960e5a 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -2640,3 +2640,41 @@ field1 field2
DROP TABLE t1;
DROP TABLE where_subselect;
# End of Bug #58782
+#
+# MDEV-8988: Apparently valid SQL query gives wrong result (nested WHERE)
+#
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int, b int, c int);
+insert into t1 select A.a + 10*B.a, A.a, A.a + 10*B.a from t0 A, t0 B;
+insert into t1 values (NULL, NULL, NULL);
+create table t2 (c int, col1 int, key(c));
+insert into t2 select t1.a, 100000 from t1;
+analyze table t2;
+Table Op Msg_type Msg_text
+test.t2 analyze status Table is already up to date
+explain
+select
+max(a)+ (select col1 from t2 where t2.c=t1.c)
+from t1
+group by t1.b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 101 Using temporary; Using filesort
+2 DEPENDENT SUBQUERY t2 ref c c 5 func 1
+select
+max(a) + (select col1 from t2 where t2.c=t1.c)
+from t1
+group by t1.b;
+max(a) + (select col1 from t2 where t2.c=t1.c)
+NULL
+100090
+100091
+100092
+100093
+100094
+100095
+100096
+100097
+100098
+100099
+drop table t0,t1,t2;
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index 531cec6b730..fe9308cd20a 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -1767,3 +1767,29 @@ DROP TABLE where_subselect;
--echo # End of Bug #58782
+--echo #
+--echo # MDEV-8988: Apparently valid SQL query gives wrong result (nested WHERE)
+--echo #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (a int, b int, c int);
+insert into t1 select A.a + 10*B.a, A.a, A.a + 10*B.a from t0 A, t0 B;
+insert into t1 values (NULL, NULL, NULL);
+
+create table t2 (c int, col1 int, key(c));
+insert into t2 select t1.a, 100000 from t1;
+analyze table t2;
+
+explain
+select
+ max(a)+ (select col1 from t2 where t2.c=t1.c)
+from t1
+group by t1.b;
+
+select
+ max(a) + (select col1 from t2 where t2.c=t1.c)
+from t1
+group by t1.b;
+
+drop table t0,t1,t2;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 20d94d47406..4759af038f9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9359,7 +9359,7 @@ static void add_not_null_conds(JOIN *join)
if (!referred_tab)
continue;
if (!(notnull= new (join->thd->mem_root)
- Item_func_isnotnull(join->thd, not_null_item)))
+ Item_func_isnotnull(join->thd, item)))
DBUG_VOID_RETURN;
/*
We need to do full fix_fields() call here in order to have correct