MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:September 9 2010 12:46pm
Subject:bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:3498)
Bug#54190
View as plain text  
#At file:///data/src/bzr/bugteam/54190/5.1-bugteam/ based on revid:davi.arnaut@stripped

 3498 Alexey Kopytov	2010-09-09
      Bug #54190: Comparison to row subquery produces incorrect
                  result
      
      Row subqueries producing no rows were not handled as UNKNOWN
      values in row comparison expressions.
      
      That was a result of the following two problems:
      
      1. Item_singlerow_subselect did not mark the resulting row
      value as NULL/UNKNOWN when no rows were produced.
      
      2. Arg_comparator::compare_row() did not take into account that
      a whole argument may be NULL rather than just individual scalar
      values.
      
      Before bug#34384 was fixed, the above problems were hidden
      because an uninitialized (i.e. without any stored value) cached
      object would appear as NULL for scalar values in a row subquery
      returning an empty result. After the fix
      Arg_comparator::compare_row() would try to evaluate
      uninitialized cached objects.
      
      Fixed by removing the aforementioned problems.
     @ mysql-test/r/row.result
        Added a test case for bug #54190.
     @ mysql-test/r/subselect.result
        Updated the result for a test relying on wrong behavior.
     @ mysql-test/t/row.test
        Added a test case for bug #54190.
     @ sql/item_cmpfunc.cc
        If either of the argument rows is NULL, return NULL as the
        result of comparison.
     @ sql/item_subselect.cc
        Adjust null_value for Item_singlerow_subselect depending on
        whether a row has been produced by the row subquery.

    modified:
      mysql-test/r/row.result
      mysql-test/r/subselect.result
      mysql-test/t/row.test
      sql/item_cmpfunc.cc
      sql/item_subselect.cc
=== modified file 'mysql-test/r/row.result'
--- a/mysql-test/r/row.result	2010-04-16 11:42:34 +0000
+++ b/mysql-test/r/row.result	2010-09-09 12:46:13 +0000
@@ -466,3 +466,26 @@ SELECT 1 FROM t1 WHERE ROW(a, b) >=
 ROW('1', (SELECT 1 FROM t1 WHERE a > 1234));
 1
 DROP TABLE t1;
+#
+# Bug #54190: Comparison to row subquery produces incorrect result
+# 
+SELECT ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0);
+ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0)
+NULL
+SELECT ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0);
+ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0)
+NULL
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 () VALUES (1), (2), (3);
+SELECT ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0);
+ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0)
+NULL
+SELECT ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0);
+ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0)
+NULL
+SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0);
+i
+SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0);
+i
+DROP TABLE t1;
+End of 5.1 tests

=== modified file 'mysql-test/r/subselect.result'
--- a/mysql-test/r/subselect.result	2010-04-15 14:04:24 +0000
+++ b/mysql-test/r/subselect.result	2010-09-09 12:46:13 +0000
@@ -922,7 +922,7 @@ select a, (select a,b,c from t1 where t1
 a	(select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a')	(select c from t1 where a=t2.a)
 1	1	a
 2	0	b
-NULL	0	NULL
+NULL	NULL	NULL
 select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2;
 a	(select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b')	(select c from t1 where a=t2.a)
 1	0	a
@@ -932,7 +932,7 @@ select a, (select a,b,c from t1 where t1
 a	(select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c')	(select c from t1 where a=t2.a)
 1	0	a
 2	0	b
-NULL	0	NULL
+NULL	NULL	NULL
 drop table t1,t2;
 create table t1 (a int, b real, c varchar(10));
 insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');

=== modified file 'mysql-test/t/row.test'
--- a/mysql-test/t/row.test	2010-04-16 11:42:34 +0000
+++ b/mysql-test/t/row.test	2010-09-09 12:46:13 +0000
@@ -266,3 +266,22 @@ SELECT 1 FROM t1 WHERE ROW(a, b) >=
 ROW('1', (SELECT 1 FROM t1 WHERE a > 1234));
 --enable_warnings
 DROP TABLE t1;
+
+--echo #
+--echo # Bug #54190: Comparison to row subquery produces incorrect result
+--echo # 
+
+SELECT ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0);
+SELECT ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0);
+
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 () VALUES (1), (2), (3);
+
+SELECT ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0);
+SELECT ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0);
+SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0);
+SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0);
+
+DROP TABLE t1;
+
+--echo End of 5.1 tests

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2010-08-05 10:42:14 +0000
+++ b/sql/item_cmpfunc.cc	2010-09-09 12:46:13 +0000
@@ -1583,6 +1583,13 @@ int Arg_comparator::compare_row()
   bool was_null= 0;
   (*a)->bring_value();
   (*b)->bring_value();
+
+  if ((*a)->null_value || (*b)->null_value)
+  {
+    owner->null_value= 1;
+    return -1;
+  }
+
   uint n= (*a)->cols();
   for (uint i= 0; i<n; i++)
   {

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2010-06-10 20:45:22 +0000
+++ b/sql/item_subselect.cc	2010-09-09 12:46:13 +0000
@@ -566,7 +566,10 @@ bool Item_singlerow_subselect::null_insi
 
 void Item_singlerow_subselect::bring_value()
 {
-  exec();
+  if (!exec() && assigned())
+    null_value= 0;
+  else
+    reset();
 }
 
 double Item_singlerow_subselect::val_real()


Attachment: [text/bzr-bundle] bzr/alexey.kopytov@sun.com-20100909124613-f355so4tg6t66nqx.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:3498)Bug#54190Alexey Kopytov9 Sep