[Commits] Rev 3863: Fix for MDEV-4836 fix: take into account situation where "notnull_col IS NULL" is not in file:///data0/psergey/dev2/5.5-pull2/

Sergey Petrunya psergey at askmonty.org
Mon Aug 26 20:38:05 EEST 2013


At file:///data0/psergey/dev2/5.5-pull2/

------------------------------------------------------------
revno: 3863
revision-id: psergey at askmonty.org-20130826173804-fl2mdyqvottvjvr7
parent: psergey at askmonty.org-20130826123158-016kvy1cdp3cozr9
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-pull2
timestamp: Mon 2013-08-26 21:38:04 +0400
message:
  Fix for MDEV-4836 fix: take into account situation where "notnull_col IS NULL" is not 
  a direct child of the WHERE clause item, but rather is embedded inside Item_cond_and or 
  Item_cond_or.
=== modified file 'mysql-test/r/join_outer.result'
--- a/mysql-test/r/join_outer.result	2013-08-26 12:31:58 +0000
+++ b/mysql-test/r/join_outer.result	2013-08-26 17:38:04 +0000
@@ -2150,6 +2150,14 @@ id	d	i
 1	0000-00-00	NULL
 2	0000-00-00	NULL
 DROP TABLE t1,t2;
+CREATE TABLE t1 (i1 INT, d1 DATE NOT NULL);
+INSERT INTO t1 VALUES (1,'2012-12-21'),(2,'0000-00-00');
+CREATE TABLE t2 (i2 INT, j2 INT);
+INSERT INTO t2 VALUES (1,10),(2,20);
+SELECT * FROM t1 LEFT JOIN t2 ON i1 = j2 WHERE d1 IS NULL AND 1 OR i1 = i2;
+i1	d1	i2	j2
+2	0000-00-00	NULL	NULL
+DROP TABLE t1,t2;
 #
 # Bug mdev-4942: LEFT JOIN with conjunctive 
 #                <non-nullable datetime field> IS NULL in WHERE 

=== modified file 'mysql-test/r/join_outer_jcl6.result'
--- a/mysql-test/r/join_outer_jcl6.result	2013-08-26 12:31:58 +0000
+++ b/mysql-test/r/join_outer_jcl6.result	2013-08-26 17:38:04 +0000
@@ -2161,6 +2161,14 @@ id	d	i
 1	0000-00-00	NULL
 2	0000-00-00	NULL
 DROP TABLE t1,t2;
+CREATE TABLE t1 (i1 INT, d1 DATE NOT NULL);
+INSERT INTO t1 VALUES (1,'2012-12-21'),(2,'0000-00-00');
+CREATE TABLE t2 (i2 INT, j2 INT);
+INSERT INTO t2 VALUES (1,10),(2,20);
+SELECT * FROM t1 LEFT JOIN t2 ON i1 = j2 WHERE d1 IS NULL AND 1 OR i1 = i2;
+i1	d1	i2	j2
+2	0000-00-00	NULL	NULL
+DROP TABLE t1,t2;
 #
 # Bug mdev-4942: LEFT JOIN with conjunctive 
 #                <non-nullable datetime field> IS NULL in WHERE 

=== modified file 'mysql-test/t/join_outer.test'
--- a/mysql-test/t/join_outer.test	2013-08-26 12:31:58 +0000
+++ b/mysql-test/t/join_outer.test	2013-08-26 17:38:04 +0000
@@ -1696,6 +1696,17 @@ CREATE TABLE t2 (i INT);
 SELECT * FROM t1 LEFT JOIN t2 ON (id=i) WHERE NULL OR d IS NULL;
 DROP TABLE t1,t2;
 
+
+CREATE TABLE t1 (i1 INT, d1 DATE NOT NULL);
+INSERT INTO t1 VALUES (1,'2012-12-21'),(2,'0000-00-00');
+
+CREATE TABLE t2 (i2 INT, j2 INT);
+INSERT INTO t2 VALUES (1,10),(2,20);
+
+SELECT * FROM t1 LEFT JOIN t2 ON i1 = j2 WHERE d1 IS NULL AND 1 OR i1 = i2;
+DROP TABLE t1,t2;
+
+
 --echo #
 --echo # Bug mdev-4942: LEFT JOIN with conjunctive 
 --echo #                <non-nullable datetime field> IS NULL in WHERE 

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2013-08-26 12:31:58 +0000
+++ b/sql/item_cmpfunc.cc	2013-08-26 17:38:04 +0000
@@ -4302,7 +4302,7 @@ Item_cond::fix_fields(THD *thd, Item **r
     used_tables_cache|=     item->used_tables();
     if (item->const_item())
     {
-      if (!item->is_expensive() && !cond_is_datetime_is_null(item) && 
+      if (!item->is_expensive() && !cond_has_datetime_is_null(item) && 
           item->val_int() == 0)
       {
         /* 
@@ -4355,7 +4355,7 @@ Item_cond::eval_not_null_tables(uchar *o
     table_map tmp_table_map;
     if (item->const_item())
     {
-      if (!item->is_expensive() && !cond_is_datetime_is_null(item) && 
+      if (!item->is_expensive() && !cond_has_datetime_is_null(item) && 
           item->val_int() == 0)
       {
         /* 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2013-08-26 12:31:58 +0000
+++ b/sql/sql_select.cc	2013-08-26 17:38:04 +0000
@@ -13526,6 +13526,28 @@ void propagate_new_equalities(THD *thd,
   }          
 } 
 
+/*
+  Check if cond_is_datetime_is_null() is true for the condition cond, or 
+  for any of its AND/OR-children
+*/
+bool cond_has_datetime_is_null(Item *cond)
+{
+  if (cond_is_datetime_is_null(cond))
+    return true;
+
+  if (cond->type() == Item::COND_ITEM)
+  {
+    List<Item> *cond_arg_list= ((Item_cond*) cond)->argument_list();
+    List_iterator<Item> li(*cond_arg_list);
+    Item *item;
+    while ((item= li++))
+    {
+      if (cond_has_datetime_is_null(item))
+        return true;
+    }
+  }
+  return false;
+}
 
 /*
   Check if passed condtition has for of

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2013-08-23 12:32:56 +0000
+++ b/sql/sql_select.h	2013-08-26 17:38:04 +0000
@@ -1796,6 +1796,7 @@ bool const_expression_in_where(COND *con
                                Field *comp_field= NULL,
                                Item **const_item= NULL);
 bool cond_is_datetime_is_null(Item *cond);
+bool cond_has_datetime_is_null(Item *cond);
 
 /* Table elimination entry point function */
 void eliminate_tables(JOIN *join);



More information about the commits mailing list