Commit 7ebd12e7 authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: VIEW of UNION [fixes #293]

parent d70bb5e6
...@@ -73,17 +73,17 @@ prepare stmt from concat(a, b, c); ...@@ -73,17 +73,17 @@ prepare stmt from concat(a, b, c);
execute stmt; execute stmt;
deallocate prepare stmt; deallocate prepare stmt;
end~~ end~~
create table t1 (x int) with system versioning engine innodb; create or replace table t1 (x int) with system versioning engine innodb;
insert into t1 values (1); insert into t1 values (1);
select now(6) into @t1; select now(6) into @t1;
update t1 set x= 2; update t1 set x= 2;
select now(6) into @t2; select now(6) into @t2;
delete from t1; delete from t1;
set @vt1= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'"); set @vt1= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
prepare stmt from @vt1; prepare stmt from @vt1;
execute stmt; execute stmt;
drop prepare stmt; drop prepare stmt;
set @vt2= concat("create view vt2 as select *, sys_trx_end from t1 for system_time as of timestamp '", @t2, "'"); set @vt2= concat("create or replace view vt2 as select *, sys_trx_end from t1 for system_time as of timestamp '", @t2, "'");
prepare stmt from @vt2; prepare stmt from @vt2;
execute stmt; execute stmt;
drop prepare stmt; drop prepare stmt;
...@@ -170,8 +170,10 @@ select * from vt1 for system_time all; ...@@ -170,8 +170,10 @@ select * from vt1 for system_time all;
x x
1 1
2 2
# VIEW with parameters [#151]
create or replace table t1 (x int) with system versioning; create or replace table t1 (x int) with system versioning;
create or replace view vt1(c) as select x from t1; create or replace view vt1(c) as select x from t1;
# VIEW over JOIN of versioned tables [#153]
create or replace table t1 (a int) with system versioning engine innodb; create or replace table t1 (a int) with system versioning engine innodb;
create or replace table t2 (b int) with system versioning engine innodb; create or replace table t2 (b int) with system versioning engine innodb;
insert into t1 values (1); insert into t1 values (1);
...@@ -183,6 +185,7 @@ a b ...@@ -183,6 +185,7 @@ a b
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2; create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
select * from vt12; select * from vt12;
a b a b
# VIEW improvements [#183]
create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2; create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2;
ERROR HY000: Creating VIEW `vt1` is prohibited: system fields from multiple tables `t1`, `t2` in query! ERROR HY000: Creating VIEW `vt1` is prohibited: system fields from multiple tables `t1`, `t2` in query!
create or replace view vt1 as select a, t1.sys_trx_end, t2.sys_trx_end from t1, t2; create or replace view vt1 as select a, t1.sys_trx_end, t2.sys_trx_end from t1, t2;
...@@ -200,6 +203,7 @@ create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2; ...@@ -200,6 +203,7 @@ create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2;
show create view vt1; show create view vt1;
View Create View character_set_client collation_connection View Create View character_set_client collation_connection
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`a` AS `a`,`t2`.`sys_trx_end` AS `endo`,`t2`.`sys_trx_start` AS `sys_trx_start` from ((`t3` join `t1` FOR SYSTEM_TIME ALL) join `t2` FOR SYSTEM_TIME ALL) where `t1`.`sys_trx_end` = 18446744073709551615 and `t2`.`sys_trx_end` = 18446744073709551615 latin1 latin1_swedish_ci vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`a` AS `a`,`t2`.`sys_trx_end` AS `endo`,`t2`.`sys_trx_start` AS `sys_trx_start` from ((`t3` join `t1` FOR SYSTEM_TIME ALL) join `t2` FOR SYSTEM_TIME ALL) where `t1`.`sys_trx_end` = 18446744073709551615 and `t2`.`sys_trx_end` = 18446744073709551615 latin1 latin1_swedish_ci
# VIEW over UNION [#269]
create or replace view vt1 as select * from t1 union select * from t1; create or replace view vt1 as select * from t1 union select * from t1;
select * from vt1; select * from vt1;
a a
......
-- source include/have_innodb.inc -- source include/have_innodb.inc
-- source suite/versioning/common.inc -- source suite/versioning/common.inc
create table t1 (x int) with system versioning engine innodb; create or replace table t1 (x int) with system versioning engine innodb;
insert into t1 values (1); insert into t1 values (1);
select now(6) into @t1; select now(6) into @t1;
...@@ -10,10 +10,10 @@ update t1 set x= 2; ...@@ -10,10 +10,10 @@ update t1 set x= 2;
select now(6) into @t2; select now(6) into @t2;
delete from t1; delete from t1;
set @vt1= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'"); set @vt1= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
prepare stmt from @vt1; execute stmt; drop prepare stmt; prepare stmt from @vt1; execute stmt; drop prepare stmt;
set @vt2= concat("create view vt2 as select *, sys_trx_end from t1 for system_time as of timestamp '", @t2, "'"); set @vt2= concat("create or replace view vt2 as select *, sys_trx_end from t1 for system_time as of timestamp '", @t2, "'");
prepare stmt from @vt2; execute stmt; drop prepare stmt; prepare stmt from @vt2; execute stmt; drop prepare stmt;
select * from vt1 for system_time all; select * from vt1 for system_time all;
...@@ -60,9 +60,11 @@ prepare stmt from @tmp; execute stmt; drop prepare stmt; ...@@ -60,9 +60,11 @@ prepare stmt from @tmp; execute stmt; drop prepare stmt;
select * from vt1 for system_time all; select * from vt1 for system_time all;
--echo # VIEW with parameters [#151]
create or replace table t1 (x int) with system versioning; create or replace table t1 (x int) with system versioning;
create or replace view vt1(c) as select x from t1; create or replace view vt1(c) as select x from t1;
--echo # VIEW over JOIN of versioned tables [#153]
create or replace table t1 (a int) with system versioning engine innodb; create or replace table t1 (a int) with system versioning engine innodb;
create or replace table t2 (b int) with system versioning engine innodb; create or replace table t2 (b int) with system versioning engine innodb;
insert into t1 values (1); insert into t1 values (1);
...@@ -72,6 +74,7 @@ select * from vt12; ...@@ -72,6 +74,7 @@ select * from vt12;
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2; create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
select * from vt12; select * from vt12;
--echo # VIEW improvements [#183]
--error ER_VERS_VIEW_PROHIBITED --error ER_VERS_VIEW_PROHIBITED
create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2; create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2;
--error ER_VERS_VIEW_PROHIBITED --error ER_VERS_VIEW_PROHIBITED
...@@ -85,6 +88,7 @@ show create view vt1; ...@@ -85,6 +88,7 @@ show create view vt1;
create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2; create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2;
show create view vt1; show create view vt1;
--echo # VIEW over UNION [#269]
create or replace view vt1 as select * from t1 union select * from t1; create or replace view vt1 as select * from t1 union select * from t1;
select * from vt1; select * from vt1;
......
...@@ -6041,14 +6041,9 @@ class Item_type_holder: public Item, ...@@ -6041,14 +6041,9 @@ class Item_type_holder: public Item,
{ {
protected: protected:
TYPELIB *enum_set_typelib; TYPELIB *enum_set_typelib;
public: private:
Item_type_holder(THD *thd, Item *item) void init_flags(Item *item)
:Item(thd, item),
Type_handler_hybrid_field_type(item->real_type_handler()),
enum_set_typelib(0)
{ {
DBUG_ASSERT(item->fixed);
maybe_null= item->maybe_null;
if (item->real_type() == Item::FIELD_ITEM) if (item->real_type() == Item::FIELD_ITEM)
{ {
Item_field *item_field= (Item_field *)item->real_item(); Item_field *item_field= (Item_field *)item->real_item();
...@@ -6056,19 +6051,32 @@ class Item_type_holder: public Item, ...@@ -6056,19 +6051,32 @@ class Item_type_holder: public Item,
(VERS_SYS_START_FLAG | VERS_SYS_END_FLAG)); (VERS_SYS_START_FLAG | VERS_SYS_END_FLAG));
} }
} }
public:
Item_type_holder(THD *thd, Item *item)
:Item(thd, item),
Type_handler_hybrid_field_type(item->real_type_handler()),
enum_set_typelib(0),
flags(0)
{
DBUG_ASSERT(item->fixed);
maybe_null= item->maybe_null;
init_flags(item);
}
Item_type_holder(THD *thd, Item_type_holder(THD *thd,
const LEX_CSTRING *name_arg, Item *item,
const Type_handler *handler, const Type_handler *handler,
const Type_all_attributes *attr, const Type_all_attributes *attr,
bool maybe_null_arg) bool maybe_null_arg)
:Item(thd), :Item(thd),
Type_handler_hybrid_field_type(handler), Type_handler_hybrid_field_type(handler),
Type_geometry_attributes(handler, attr), Type_geometry_attributes(handler, attr),
enum_set_typelib(attr->get_typelib()) enum_set_typelib(attr->get_typelib()),
flags(0)
{ {
name= *name_arg; name= item->name;
Type_std_attributes::set(*attr); Type_std_attributes::set(*attr);
maybe_null= maybe_null_arg; maybe_null= maybe_null_arg;
init_flags(item);
} }
const Type_handler *type_handler() const const Type_handler *type_handler() const
......
...@@ -241,7 +241,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl, ...@@ -241,7 +241,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl,
/* Error's in 'new' will be detected after loop */ /* Error's in 'new' will be detected after loop */
Item_type_holder *new_holder= new (thd->mem_root) Item_type_holder *new_holder= new (thd->mem_root)
Item_type_holder(thd, Item_type_holder(thd,
&item->name, item,
holders[pos].type_handler(), holders[pos].type_handler(),
&holders[pos]/*Type_all_attributes*/, &holders[pos]/*Type_all_attributes*/,
holders[pos].get_maybe_null()); holders[pos].get_maybe_null());
......
...@@ -802,7 +802,7 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg, ...@@ -802,7 +802,7 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg,
/* Error's in 'new' will be detected after loop */ /* Error's in 'new' will be detected after loop */
types.push_back(new (thd_arg->mem_root) types.push_back(new (thd_arg->mem_root)
Item_type_holder(thd_arg, Item_type_holder(thd_arg,
&item_tmp->name, item_tmp,
holders[pos].type_handler(), holders[pos].type_handler(),
&holders[pos]/*Type_all_attributes*/, &holders[pos]/*Type_all_attributes*/,
holders[pos].get_maybe_null())); holders[pos].get_maybe_null()));
......
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