Loading mysql-test/r/subselect.result +13 −0 Original line number Diff line number Diff line Loading @@ -3013,3 +3013,16 @@ t3 CREATE TABLE `t3` ( `a` datetime default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1,t2,t3; CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1), (2); SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0; a SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; a 1 2 EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE DROP TABLE t1; mysql-test/t/subselect.test +12 −0 Original line number Diff line number Diff line Loading @@ -1981,4 +1981,16 @@ SHOW CREATE TABLE t3; DROP TABLE t1,t2,t3; # # Bug 24670: subquery witout tables but with a WHERE clause # CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1), (2); SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0; SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; DROP TABLE t1; # End of 4.1 tests sql/item_subselect.cc +17 −2 Original line number Diff line number Diff line Loading @@ -350,6 +350,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ !(select_lex->item_list.head()->type() == FIELD_ITEM || select_lex->item_list.head()->type() == REF_ITEM) && !join->conds && !join->having && /* switch off this optimisation for prepare statement, because we do not rollback this changes Loading @@ -374,8 +375,6 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ substitution->walk(&Item::remove_dependence_processor, (byte *) select_lex->outer_select()); /* SELECT without FROM clause can't have WHERE or HAVING clause */ DBUG_ASSERT(join->conds == 0 && join->having == 0); return RES_REDUCE; } return RES_OK; Loading Loading @@ -1795,6 +1794,22 @@ bool subselect_single_select_engine::no_tables() } /* Check statically whether the subquery can return NULL SINOPSYS subselect_single_select_engine::may_be_null() RETURN FALSE can guarantee that the subquery never return NULL TRUE otherwise */ bool subselect_single_select_engine::may_be_null() { return ((no_tables() && !join->conds && !join->having) ? maybe_null : 1); } /* Report about presence of tables in subquery Loading sql/item_subselect.h +2 −1 Original line number Diff line number Diff line Loading @@ -301,7 +301,7 @@ class subselect_engine: public Sql_alloc enum Item_result type() { return res_type; } enum_field_types field_type() { return res_field_type; } virtual void exclude()= 0; bool may_be_null() { return maybe_null; }; virtual bool may_be_null() { return maybe_null; }; virtual table_map upper_select_const_tables()= 0; static table_map calc_const_tables(TABLE_LIST *); virtual void print(String *str)= 0; Loading Loading @@ -335,6 +335,7 @@ class subselect_single_select_engine: public subselect_engine void print (String *str); int change_item(Item_subselect *si, select_subselect *result); bool no_tables(); bool may_be_null(); }; Loading Loading
mysql-test/r/subselect.result +13 −0 Original line number Diff line number Diff line Loading @@ -3013,3 +3013,16 @@ t3 CREATE TABLE `t3` ( `a` datetime default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1,t2,t3; CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1), (2); SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0; a SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; a 1 2 EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE DROP TABLE t1;
mysql-test/t/subselect.test +12 −0 Original line number Diff line number Diff line Loading @@ -1981,4 +1981,16 @@ SHOW CREATE TABLE t3; DROP TABLE t1,t2,t3; # # Bug 24670: subquery witout tables but with a WHERE clause # CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1), (2); SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0; SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; DROP TABLE t1; # End of 4.1 tests
sql/item_subselect.cc +17 −2 Original line number Diff line number Diff line Loading @@ -350,6 +350,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ !(select_lex->item_list.head()->type() == FIELD_ITEM || select_lex->item_list.head()->type() == REF_ITEM) && !join->conds && !join->having && /* switch off this optimisation for prepare statement, because we do not rollback this changes Loading @@ -374,8 +375,6 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ substitution->walk(&Item::remove_dependence_processor, (byte *) select_lex->outer_select()); /* SELECT without FROM clause can't have WHERE or HAVING clause */ DBUG_ASSERT(join->conds == 0 && join->having == 0); return RES_REDUCE; } return RES_OK; Loading Loading @@ -1795,6 +1794,22 @@ bool subselect_single_select_engine::no_tables() } /* Check statically whether the subquery can return NULL SINOPSYS subselect_single_select_engine::may_be_null() RETURN FALSE can guarantee that the subquery never return NULL TRUE otherwise */ bool subselect_single_select_engine::may_be_null() { return ((no_tables() && !join->conds && !join->having) ? maybe_null : 1); } /* Report about presence of tables in subquery Loading
sql/item_subselect.h +2 −1 Original line number Diff line number Diff line Loading @@ -301,7 +301,7 @@ class subselect_engine: public Sql_alloc enum Item_result type() { return res_type; } enum_field_types field_type() { return res_field_type; } virtual void exclude()= 0; bool may_be_null() { return maybe_null; }; virtual bool may_be_null() { return maybe_null; }; virtual table_map upper_select_const_tables()= 0; static table_map calc_const_tables(TABLE_LIST *); virtual void print(String *str)= 0; Loading Loading @@ -335,6 +335,7 @@ class subselect_single_select_engine: public subselect_engine void print (String *str); int change_item(Item_subselect *si, select_subselect *result); bool no_tables(); bool may_be_null(); }; Loading