mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fix for bug#58818: Incorrect result for IN/ANY subquery
If the ::single_value_transformer() find an existing HAVING condition it used
to do the transformation:
1) HAVING cond -> (HAVING Cond) AND (cond_guard (Item_ref_null_helper(...))
As the AND condition in 1) is Mc'Carty evaluated, the
right side of the AND cond should be executed only if the
original 'HAVING evaluated' to true.
However, as we failed to set 'top_level' for the tranformed HAVING condition,
'abort_on_null' was FALSE after transformation. An
UNKNOWN having condition will then not terminate evaluation of the
transformed having condition, and we incorrectly continued
into the Item_ref_null_helper() part.
This commit is contained in:
@@ -5004,6 +5004,58 @@ ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
|
||||
SELECT * FROM t2 UNION SELECT * FROM t2
|
||||
ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
|
||||
DROP TABLE t1,t2;
|
||||
#
|
||||
# Bug #58818: Incorrect result for IN/ANY subquery
|
||||
# with HAVING condition
|
||||
#
|
||||
CREATE TABLE t1(i INT);
|
||||
INSERT INTO t1 VALUES (1), (2), (3);
|
||||
CREATE TABLE t1s(i INT);
|
||||
INSERT INTO t1s VALUES (10), (20), (30);
|
||||
CREATE TABLE t2s(i INT);
|
||||
INSERT INTO t2s VALUES (100), (200), (300);
|
||||
SELECT * FROM t1
|
||||
WHERE t1.i NOT IN
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
);
|
||||
i
|
||||
1
|
||||
2
|
||||
3
|
||||
SELECT * FROM t1
|
||||
WHERE t1.I IN
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
) IS UNKNOWN;
|
||||
i
|
||||
SELECT * FROM t1
|
||||
WHERE NOT t1.I = ANY
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
);
|
||||
i
|
||||
1
|
||||
2
|
||||
3
|
||||
SELECT * FROM t1
|
||||
WHERE t1.i = ANY (
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
) IS UNKNOWN;
|
||||
i
|
||||
DROP TABLE t1,t1s,t2s;
|
||||
End of 5.1 tests
|
||||
#
|
||||
# Bug #57704: Cleanup code dies with void TABLE::set_keyread(bool):
|
||||
|
||||
@@ -3945,6 +3945,55 @@ SELECT * FROM t2 UNION SELECT * FROM t2
|
||||
DROP TABLE t1,t2;
|
||||
--enable_result_log
|
||||
|
||||
--echo #
|
||||
--echo # Bug #58818: Incorrect result for IN/ANY subquery
|
||||
--echo # with HAVING condition
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1(i INT);
|
||||
INSERT INTO t1 VALUES (1), (2), (3);
|
||||
CREATE TABLE t1s(i INT);
|
||||
INSERT INTO t1s VALUES (10), (20), (30);
|
||||
CREATE TABLE t2s(i INT);
|
||||
INSERT INTO t2s VALUES (100), (200), (300);
|
||||
|
||||
SELECT * FROM t1
|
||||
WHERE t1.i NOT IN
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
);
|
||||
|
||||
SELECT * FROM t1
|
||||
WHERE t1.I IN
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
) IS UNKNOWN;
|
||||
|
||||
SELECT * FROM t1
|
||||
WHERE NOT t1.I = ANY
|
||||
(
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
);
|
||||
|
||||
SELECT * FROM t1
|
||||
WHERE t1.i = ANY (
|
||||
SELECT STRAIGHT_JOIN t2s.i
|
||||
FROM
|
||||
t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i
|
||||
HAVING t2s.i = 999
|
||||
) IS UNKNOWN;
|
||||
|
||||
DROP TABLE t1,t1s,t2s;
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
||||
--echo #
|
||||
|
||||
@@ -1116,6 +1116,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
|
||||
select_lex->having= join->having= and_items(join->having, item);
|
||||
if (join->having == item)
|
||||
item->name= (char*)in_having_cond;
|
||||
select_lex->having->top_level_item();
|
||||
select_lex->having_fix_field= 1;
|
||||
/*
|
||||
we do not check join->having->fixed, because Item_and (from and_items)
|
||||
|
||||
Reference in New Issue
Block a user