Commit 0c591895 authored by unknown's avatar unknown

fixed staistic of subquery if outer field resolved in merged view (BUG#5247)


mysql-test/r/view.result:
  problem with used_tables() of outer reference resolved in VIEW
mysql-test/t/view.test:
  problem with used_tables() of outer reference resolved in VIEW
sql/item.cc:
  fixed staistic of subquery if outer field resolved in merged view
parent 574c6519
...@@ -1230,3 +1230,11 @@ c ...@@ -1230,3 +1230,11 @@ c
drop view v; drop view v;
drop table t; drop table t;
create table t1 (a int, b int);
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
create view v1(c) as select a+1 from t1 where b >= 4;
select c from v1 where exists (select * from t1 where a=2 and b=c);
c
4
drop view v1;
drop table t1;
...@@ -1178,3 +1178,13 @@ insert into v ...@@ -1178,3 +1178,13 @@ insert into v
select * from v; select * from v;
drop view v; drop view v;
drop table t; drop table t;
#
# problem with used_tables() of outer reference resolved in VIEW
#
create table t1 (a int, b int);
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
create view v1(c) as select a+1 from t1 where b >= 4;
select c from v1 where exists (select * from t1 where a=2 and b=c);
drop view v1;
drop table t1;
...@@ -1302,11 +1302,21 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -1302,11 +1302,21 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
table_list, ref, table_list, ref,
0, 1)) != not_found_field) 0, 1)) != not_found_field)
{ {
if (tmp && tmp != view_ref_found) if (tmp)
{
if (tmp != view_ref_found)
{ {
prev_subselect_item->used_tables_cache|= tmp->table->map; prev_subselect_item->used_tables_cache|= tmp->table->map;
prev_subselect_item->const_item_cache= 0; prev_subselect_item->const_item_cache= 0;
} }
else
{
prev_subselect_item->used_tables_cache|=
(*ref)->used_tables();
prev_subselect_item->const_item_cache&=
(*ref)->const_item();
}
}
break; break;
} }
if (sl->resolve_mode == SELECT_LEX::SELECT_MODE && if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
...@@ -2029,11 +2039,21 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) ...@@ -2029,11 +2039,21 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
table_list, reference, table_list, reference,
0, 1)) != not_found_field) 0, 1)) != not_found_field)
{ {
if (tmp && tmp != view_ref_found) if (tmp)
{
if (tmp != view_ref_found)
{ {
prev_subselect_item->used_tables_cache|= tmp->table->map; prev_subselect_item->used_tables_cache|= tmp->table->map;
prev_subselect_item->const_item_cache= 0; prev_subselect_item->const_item_cache= 0;
} }
else
{
prev_subselect_item->used_tables_cache|=
(*reference)->used_tables();
prev_subselect_item->const_item_cache&=
(*reference)->const_item();
}
}
break; break;
} }
......
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