mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
view with WHERE in nested join (BUG#5511)
mysql-test/r/view.result: view with WHERE in nested join mysql-test/t/view.test: view with WHERE in nested join sql/table.cc: fixed merging of VIEW
This commit is contained in:
@@ -1288,3 +1288,26 @@ handler v1 open as xx;
|
||||
ERROR HY000: 'test.v1' is not BASE TABLE
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
create table t1(a int);
|
||||
insert into t1 values (0), (1), (2), (3);
|
||||
create table t2 (a int);
|
||||
insert into t2 select a from t1 where a > 1;
|
||||
create view v1 as select a from t1 where a > 1;
|
||||
select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
|
||||
a a a
|
||||
0 NULL NULL
|
||||
1 NULL NULL
|
||||
2 2 2
|
||||
2 3 2
|
||||
3 2 3
|
||||
3 3 3
|
||||
select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
|
||||
a a a
|
||||
0 NULL NULL
|
||||
1 NULL NULL
|
||||
2 2 2
|
||||
2 3 2
|
||||
3 2 3
|
||||
3 3 3
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
@@ -1258,3 +1258,16 @@ create view v1 as select * from t1;
|
||||
handler v1 open as xx;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# view with WHERE in nested join
|
||||
#
|
||||
create table t1(a int);
|
||||
insert into t1 values (0), (1), (2), (3);
|
||||
create table t2 (a int);
|
||||
insert into t2 select a from t1 where a > 1;
|
||||
create view v1 as select a from t1 where a > 1;
|
||||
select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
|
||||
select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
26
sql/table.cc
26
sql/table.cc
@@ -1583,6 +1583,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
|
||||
if (where)
|
||||
{
|
||||
Item_arena *arena= thd->current_arena, backup;
|
||||
TABLE_LIST *tbl= this;
|
||||
if (arena->is_conventional())
|
||||
arena= 0; // For easier test
|
||||
|
||||
@@ -1591,17 +1592,23 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
|
||||
|
||||
if (arena)
|
||||
thd->set_n_backup_item_arena(arena, &backup);
|
||||
if (outer_join)
|
||||
|
||||
/* Go up to join tree and try to find left join */
|
||||
for (; tbl; tbl= tbl->embedding)
|
||||
{
|
||||
/*
|
||||
Store WHERE condition to ON expression for outer join, because we
|
||||
can't use WHERE to correctly execute jeft joins on VIEWs and this
|
||||
expression will not be moved to WHERE condition (i.e. will be clean
|
||||
correctly for PS/SP)
|
||||
*/
|
||||
on_expr= and_conds(on_expr, where);
|
||||
if (tbl->outer_join)
|
||||
{
|
||||
/*
|
||||
Store WHERE condition to ON expression for outer join, because we
|
||||
can't use WHERE to correctly execute jeft joins on VIEWs and this
|
||||
expression will not be moved to WHERE condition (i.e. will be clean
|
||||
correctly for PS/SP)
|
||||
*/
|
||||
on_expr= and_conds(tbl->on_expr, where);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (tbl == 0)
|
||||
{
|
||||
/*
|
||||
It is conds of JOIN, but it will be stored in st_select_lex::prep_where
|
||||
@@ -1609,6 +1616,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
|
||||
*/
|
||||
*conds= and_conds(*conds, where);
|
||||
}
|
||||
|
||||
if (arena)
|
||||
thd->restore_backup_item_arena(arena, &backup);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user