Commit 5b441013 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-5468.

The field JOIN::select_lex->where should be updated after the call
of remove_eq_conds() in the function make_join_statistics(). This
matters for subselects.
parent 08293a35
......@@ -2348,5 +2348,32 @@ SELECT * FROM t1 AS t
WHERE a='r' AND (c,b) NOT IN (SELECT c,b FROM t2 WHERE (c,b)=(t.c,t.b));
a b c d
DROP TABLE t1, t2;
#
# MDEV-5468: assertion failure with a simplified condition in subselect
#
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1);
CREATE TABLE t2 ( pk int PRIMARY KEY, c INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,4), (2,6);
SELECT ( SELECT MAX(b) FROM t1, t2 WHERE pk = a AND b < from_sq.c ) AS select_sq,
COUNT( DISTINCT from_sq.c )
FROM ( SELECT DISTINCT t2_1.* FROM t2 AS t2_1, t2 AS t2_2 ) AS from_sq
GROUP BY select_sq ;
select_sq COUNT( DISTINCT from_sq.c )
1 2
DROP TABLE t1,t2;
CREATE TABLE t1 (id int, a2 char(2), a3 char(3)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,'BE','BEL');
CREATE TABLE t2 (id int, a2 char(2), a3 char(3)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,'BE','BEL'), (2,'MX','MEX');
CREATE VIEW v2 AS SELECT DISTINCT * FROM t2;
SELECT * FROM t1 AS outer_t1, v2
WHERE v2.a3 = outer_t1.a3
AND EXISTS ( SELECT * FROM t1 WHERE a2 < v2.a2 AND id = outer_t1.id )
AND outer_t1.a3 < 'J'
ORDER BY v2.id;
id a2 a3 id a2 a3
DROP VIEW v2;
DROP TABLE t1,t2;
SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;
......@@ -1936,5 +1936,39 @@ SELECT * FROM t1 AS t
DROP TABLE t1, t2;
--echo #
--echo # MDEV-5468: assertion failure with a simplified condition in subselect
--echo #
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1);
CREATE TABLE t2 ( pk int PRIMARY KEY, c INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,4), (2,6);
SELECT ( SELECT MAX(b) FROM t1, t2 WHERE pk = a AND b < from_sq.c ) AS select_sq,
COUNT( DISTINCT from_sq.c )
FROM ( SELECT DISTINCT t2_1.* FROM t2 AS t2_1, t2 AS t2_2 ) AS from_sq
GROUP BY select_sq ;
DROP TABLE t1,t2;
CREATE TABLE t1 (id int, a2 char(2), a3 char(3)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,'BE','BEL');
CREATE TABLE t2 (id int, a2 char(2), a3 char(3)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,'BE','BEL'), (2,'MX','MEX');
CREATE VIEW v2 AS SELECT DISTINCT * FROM t2;
SELECT * FROM t1 AS outer_t1, v2
WHERE v2.a3 = outer_t1.a3
AND EXISTS ( SELECT * FROM t1 WHERE a2 < v2.a2 AND id = outer_t1.id )
AND outer_t1.a3 < 'J'
ORDER BY v2.id;
DROP VIEW v2;
DROP TABLE t1,t2;
SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;
......@@ -3535,6 +3535,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
if (conds && const_count)
{
conds= remove_eq_conds(join->thd, conds, &join->cond_value);
join->select_lex->where= conds;
if (join->cond_value == Item::COND_FALSE)
{
join->impossible_where= true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment