Commit 362c2bca authored by unknown's avatar unknown

Fix of MDEV-3799.

Find left table in right join (which turned to left join by reordering tables in join list but phisical order of tables of SELECT left as it was).
parent d2d6c8b8
......@@ -1677,6 +1677,7 @@ SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b AND t.c = t1.a;
b c a
8 c c
EXPLAIN EXTENDED
SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
......@@ -1691,6 +1692,7 @@ SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b <> 0 AND t.c = t1.a;
b c a
8 c c
INSERT INTO t3 VALUES (100), (200);
EXPLAIN EXTENDED
SELECT t.b, t.c, t1.a
......@@ -1706,7 +1708,7 @@ SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b AND t.c = t1.a;
b c a
NULL NULL c
8 c c
EXPLAIN EXTENDED
SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
......@@ -1721,7 +1723,7 @@ SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b <> 0 AND t.c = t1.a;
b c a
NULL NULL c
8 c c
SET optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2,t3;
#
......
......@@ -4588,6 +4588,28 @@ INSERT INTO v2 (f1, f2) VALUES (1, 2);
ERROR HY000: Can not modify more than one base table through a join view 'test.v2'
drop view v4,v3,v2,v1;
drop table t1,t2;
#
# MDEV-3799 fix of above bugfix (MDEV-589)
# Wrong result (NULLs instead of real values) with RIGHT JOIN
# in a FROM subquery and derived_merge=on
#
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (7),(8);
SELECT * FROM (
SELECT * FROM t1 RIGHT JOIN t2 ON f1 = f2
) AS alias;
f1 f2
NULL 7
NULL 8
SELECT * FROM (
SELECT * FROM t2 LEFT JOIN t1 ON f1 = f2
) AS alias;
f2 f1
7 NULL
8 NULL
drop tables t1,t2;
# -----------------------------------------------------------------
# -- End of 5.3 tests.
# -----------------------------------------------------------------
......
......@@ -4526,6 +4526,29 @@ INSERT INTO v2 (f1, f2) VALUES (1, 2);
drop view v4,v3,v2,v1;
drop table t1,t2;
--echo #
--echo # MDEV-3799 fix of above bugfix (MDEV-589)
--echo # Wrong result (NULLs instead of real values) with RIGHT JOIN
--echo # in a FROM subquery and derived_merge=on
--echo #
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (7),(8);
SELECT * FROM (
SELECT * FROM t1 RIGHT JOIN t2 ON f1 = f2
) AS alias;
SELECT * FROM (
SELECT * FROM t2 LEFT JOIN t1 ON f1 = f2
) AS alias;
drop tables t1,t2;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.3 tests.
--echo # -----------------------------------------------------------------
......
......@@ -4462,7 +4462,16 @@ TABLE *TABLE_LIST::get_real_join_table()
tbl= (tbl->view != NULL ?
tbl->view->select_lex.get_table_list() :
tbl->derived->first_select()->get_table_list());
/* find left table in outer join on this level */
while(tbl->outer_join & JOIN_TYPE_RIGHT)
{
DBUG_ASSERT(tbl->next_local);
tbl= tbl->next_local;
}
}
return tbl->table;
}
......
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