mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fix for LP#612894 Some aggregate functions (such as MIN MAX) work incorrectly in subqueries after getting NULL value
mysql-test/r/group_by.result: Added test that showed problems that no_rows_in_results() didn't work for expressions mysql-test/r/subselect4.result: Test case for LP#612894 mysql-test/t/group_by.test: Added test that showed problems that no_rows_in_results() didn't work for expressions mysql-test/t/subselect4.test: Test case for LP#612894 sql/item.h: Added restore_to_before_no_rows_in_result() Added function processor for no_rows_in_results() and restore_to_before_no_rows_in_results() to ensure it works with functions Fix that above functions are handled by Item_ref() sql/item_func.h: Ensure that no_rows_in_results() and restore_to_before_no_rows_in_result() are called for all function arguments sql/item_sum.cc: Added restore_to_before_no_rows_in_result() to restore settings after Item_sum_hybrid::no_rows_in_result() was called. This is needed to handle the case where we have made 'make_const()' on the item in opt_sum(), but the item will be reused again in a sub query. Ignore multiple calls to no_rows_in_result() as Item_ref is calling it twice. sql/item_sum.h: Added restore_to_before_no_rows_in_result(); sql/sql_select.cc: Added reset of no_rows_in_result() for JOIN::reinit() sql/sql_select.h: Added marker if no_rows_in_result() is called.
This commit is contained in:
@@ -1809,5 +1809,22 @@ SELECT MAX(t2.a) FROM t2 LEFT JOIN t1 ON t2.a = t1.a;
|
||||
MAX(t2.a)
|
||||
2
|
||||
DROP TABLE t1, t2;
|
||||
CREATE TABLE t1 (a int(11) NOT NULL);
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (
|
||||
key_col int(11) NOT NULL,
|
||||
KEY (key_col)
|
||||
);
|
||||
INSERT INTO t2 VALUES (1),(2);
|
||||
select min(t2.key_col) from t1,t2 where t1.a=1;
|
||||
min(t2.key_col)
|
||||
1
|
||||
select min(t2.key_col) from t1,t2 where t1.a > 1000;
|
||||
min(t2.key_col)
|
||||
NULL
|
||||
select min(t2.key_col)+1 from t1,t2 where t1.a> 1000;
|
||||
min(t2.key_col)+1
|
||||
NULL
|
||||
drop table t1,t2;
|
||||
#
|
||||
# End of 5.1 tests
|
||||
|
||||
@@ -59,3 +59,26 @@ FROM t3 WHERE 1 = 0 GROUP BY 1;
|
||||
(SELECT 1 FROM t1,t2 WHERE t2.b > t3.b)
|
||||
DROP TABLE t1,t2,t3;
|
||||
End of 5.0 tests.
|
||||
CREATE TABLE t1 (col_int_nokey int(11) NOT NULL, col_varchar_nokey varchar(1) NOT NULL) engine=myisam;
|
||||
INSERT INTO t1 VALUES (2,'s'),(0,'v'),(2,'s');
|
||||
CREATE TABLE t2 (
|
||||
pk int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_key` int(11) NOT NULL,
|
||||
col_varchar_key varchar(1) NOT NULL,
|
||||
PRIMARY KEY (pk),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (4,10,'g'), (5,20,'v');
|
||||
SELECT t1.col_int_nokey,(SELECT MIN( t2_a.col_int_key ) FROM t2 t2_a, t2 t2_b, t1 t1_a WHERE t1_a.col_varchar_nokey = t2_b.col_varchar_key and t1.col_int_nokey ) as sub FROM t1;
|
||||
col_int_nokey sub
|
||||
2 10
|
||||
0 NULL
|
||||
2 10
|
||||
SELECT t1.col_int_nokey,(SELECT MIN( t2_a.col_int_key ) +1 FROM t2 t2_a, t2 t2_b, t1 t1_a WHERE t1_a.col_varchar_nokey = t2_b.col_varchar_key and t1.col_int_nokey ) as sub FROM t1;
|
||||
col_int_nokey sub
|
||||
2 11
|
||||
0 NULL
|
||||
2 11
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.1 tests.
|
||||
|
||||
@@ -1219,6 +1219,23 @@ EXPLAIN SELECT MAX(t2.a) FROM t2 LEFT JOIN t1 ON t2.a = t1.a;
|
||||
SELECT MAX(t2.a) FROM t2 LEFT JOIN t1 ON t2.a = t1.a;
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
#
|
||||
# min() returns wrong value when used in expression when there is no matching
|
||||
# rows
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (a int(11) NOT NULL);
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (
|
||||
key_col int(11) NOT NULL,
|
||||
KEY (key_col)
|
||||
);
|
||||
INSERT INTO t2 VALUES (1),(2);
|
||||
|
||||
select min(t2.key_col) from t1,t2 where t1.a=1;
|
||||
select min(t2.key_col) from t1,t2 where t1.a > 1000;
|
||||
select min(t2.key_col)+1 from t1,t2 where t1.a> 1000;
|
||||
drop table t1,t2;
|
||||
|
||||
--echo #
|
||||
|
||||
|
||||
@@ -62,3 +62,29 @@ FROM t3 WHERE 1 = 0 GROUP BY 1;
|
||||
DROP TABLE t1,t2,t3;
|
||||
|
||||
--echo End of 5.0 tests.
|
||||
|
||||
#
|
||||
# Fix for LP#612894
|
||||
# Some aggregate functions (such as MIN MAX) work incorrectly in subqueries
|
||||
# after getting NULL value
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (col_int_nokey int(11) NOT NULL, col_varchar_nokey varchar(1) NOT NULL) engine=myisam;
|
||||
INSERT INTO t1 VALUES (2,'s'),(0,'v'),(2,'s');
|
||||
CREATE TABLE t2 (
|
||||
pk int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_key` int(11) NOT NULL,
|
||||
col_varchar_key varchar(1) NOT NULL,
|
||||
PRIMARY KEY (pk),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (4,10,'g'), (5,20,'v');
|
||||
|
||||
SELECT t1.col_int_nokey,(SELECT MIN( t2_a.col_int_key ) FROM t2 t2_a, t2 t2_b, t1 t1_a WHERE t1_a.col_varchar_nokey = t2_b.col_varchar_key and t1.col_int_nokey ) as sub FROM t1;
|
||||
|
||||
SELECT t1.col_int_nokey,(SELECT MIN( t2_a.col_int_key ) +1 FROM t2 t2_a, t2 t2_b, t1 t1_a WHERE t1_a.col_varchar_nokey = t2_b.col_varchar_key and t1.col_int_nokey ) as sub FROM t1;
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo End of 5.1 tests.
|
||||
|
||||
Reference in New Issue
Block a user