summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-09-09 19:00:33 +0400
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-09-09 19:00:33 +0400
commit637c7529dec0fcc820fab0753679f94f31260a1e (patch)
tree20b533d22ea39c933ac382d5309f7502783298e9
parentd88a11a76687b8c7ae4cb0642a0977b7ca420ad0 (diff)
parentf563a012cebf217f32710b6d07f6b1ea58431146 (diff)
downloadmariadb-git-637c7529dec0fcc820fab0753679f94f31260a1e.tar.gz
Manual merge of the fix for bug #54190 and the addendum patch
to 5.5 (removed one test case as it is no longer valid).
-rw-r--r--mysql-test/r/row.result23
-rw-r--r--mysql-test/r/select.result5
-rw-r--r--mysql-test/r/subselect.result4
-rw-r--r--mysql-test/t/row.test19
-rw-r--r--mysql-test/t/select.test5
-rw-r--r--sql/item.cc5
-rw-r--r--sql/item_cmpfunc.cc7
-rw-r--r--sql/item_subselect.cc5
8 files changed, 59 insertions, 14 deletions
diff --git a/mysql-test/r/row.result b/mysql-test/r/row.result
index 2962123fcb2..789b9c4f383 100644
--- a/mysql-test/r/row.result
+++ b/mysql-test/r/row.result
@@ -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
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index e8628d72a46..4ec7a72d7c5 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -4430,11 +4430,6 @@ SELECT 1 FROM t1 WHERE a <> 1 AND NOT
ROW(1,a) <=> ROW(1,(SELECT 1 FROM t1))
INTO @var0;
ERROR 21000: Subquery returns more than 1 row
-SELECT 1 FROM t1 WHERE a <> 1 AND NOT
-ROW(a,a) <=> ROW((SELECT 1 FROM t1 WHERE 1=2),(SELECT 1 FROM t1));
-1
-1
-1
DROP TABLE t1;
#
# Bug #48458: simple query tries to allocate enormous amount of
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 72d63e47d9a..13941b56040 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -922,7 +922,7 @@ select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t
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=t2.a) = ROW(a,4,'c'),(select c from t
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');
diff --git a/mysql-test/t/row.test b/mysql-test/t/row.test
index cec44078279..fb49ce23644 100644
--- a/mysql-test/t/row.test
+++ b/mysql-test/t/row.test
@@ -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
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 495b6002986..87f36c452f2 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -3772,11 +3772,6 @@ SELECT 1 FROM t1 WHERE a <> 1 AND NOT
ROW(1,a) <=> ROW(1,(SELECT 1 FROM t1))
INTO @var0;
-# Query correctly return 2 rows since comparison a <=> fisrt_subquery is
-# always false, thus the second query is never executed.
-SELECT 1 FROM t1 WHERE a <> 1 AND NOT
-ROW(a,a) <=> ROW((SELECT 1 FROM t1 WHERE 1=2),(SELECT 1 FROM t1));
-
DROP TABLE t1;
--echo #
diff --git a/sql/item.cc b/sql/item.cc
index 427146e11dc..94c44f36ec3 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -7850,9 +7850,12 @@ bool Item_cache_row::null_inside()
void Item_cache_row::bring_value()
{
+ if (!example)
+ return;
+ example->bring_value();
+ null_value= example->null_value;
for (uint i= 0; i < item_count; i++)
values[i]->bring_value();
- return;
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index adecc19a122..efbd99c4106 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1595,6 +1595,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++)
{
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 8622e8f961d..56bd8c75a20 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -574,7 +574,10 @@ bool Item_singlerow_subselect::null_inside()
void Item_singlerow_subselect::bring_value()
{
- exec();
+ if (!exec() && assigned())
+ null_value= 0;
+ else
+ reset();
}
double Item_singlerow_subselect::val_real()