List:Commits« Previous MessageNext Message »
From:igor Date:December 12 2006 2:57am
Subject:bk commit into 4.1 tree (igor:1.2583) BUG#24670
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-12-11 18:57:23-08:00, igor@stripped +4 -0
  Fixed bug #24670: optimizations that are legal only for subqueries without tables
  and no WHERE condition were applied for any subquery without tables.
  

  mysql-test/r/subselect.result@stripped, 2006-12-11 18:57:21-08:00, igor@stripped +13 -0
    Added a test case for bug #24670.

  mysql-test/t/subselect.test@stripped, 2006-12-11 18:57:21-08:00, igor@stripped +12 -0
    Added a test case for bug #24670.

  sql/item_subselect.cc@stripped, 2006-12-11 18:57:21-08:00, igor@stripped +17 -2
    Fixed bug #24670: optimizations that are legal only for subqueries without tables
    and no WHERE condition were applied for any subquery without tables.
    
    Removed an assertion that caused an abort for subqueries without tables and no 
    WHERE condition. 
    Blocked substitution of a single-row subquery without tables for the constant 
    row from its select list when the subquery contained a WHERE condition.
    This optimization is valid only for subquries without tables with no conditions.
    Any subquery without tables with WHERE clause returns NULL if the WHERE condition
    is FALSE. Erroneously it was always considered as non-nullable that could trigger 
    another optimization concerning IS NULL predicates which is applicable only for 
    non-nullable expressions and ultimately led to a wrong result returned by the outer
    query.
    Added a proper implementation of the virtual method may_be_null for class 
    subselect_single_select_engine.

  sql/item_subselect.h@stripped, 2006-12-11 18:57:21-08:00, igor@stripped +2 -1
    Fixed bug #24670: optimizations that are legal only for subqueries without tables
    and no WHERE condition were applied for any subquery without tables.
    Made method may_by_null for class subselect_engine vvirtual.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	igor
# Host:	olga.mysql.com
# Root:	/home/igor/dev-opt/mysql-4.1-opt-bug24670

--- 1.185/mysql-test/r/subselect.result	2006-12-11 18:57:27 -08:00
+++ 1.186/mysql-test/r/subselect.result	2006-12-11 18:57:27 -08:00
@@ -3013,3 +3013,16 @@
   `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;

--- 1.162/mysql-test/t/subselect.test	2006-12-11 18:57:27 -08:00
+++ 1.163/mysql-test/t/subselect.test	2006-12-11 18:57:27 -08:00
@@ -1981,4 +1981,16 @@
 
 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

--- 1.146/sql/item_subselect.cc	2006-12-11 18:57:27 -08:00
+++ 1.147/sql/item_subselect.cc	2006-12-11 18:57:27 -08:00
@@ -350,6 +350,7 @@
       */
       !(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
@@ -374,8 +375,6 @@
     */
     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;
@@ -1792,6 +1791,22 @@
 bool subselect_single_select_engine::no_tables()
 {
   return(select_lex->table_list.elements == 0);
+}
+
+
+/*
+  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);
 }
 
 

--- 1.64/sql/item_subselect.h	2006-12-11 18:57:27 -08:00
+++ 1.65/sql/item_subselect.h	2006-12-11 18:57:27 -08:00
@@ -301,7 +301,7 @@
   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;
@@ -335,6 +335,7 @@
   void print (String *str);
   int change_item(Item_subselect *si, select_subselect *result);
   bool no_tables();
+  bool may_be_null();
 };
 
 
Thread
bk commit into 4.1 tree (igor:1.2583) BUG#24670igor12 Dec