Commit 9ba635fd authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: VIEW with UNION fix [fixes #269]

parent 7e764ae1
......@@ -187,6 +187,10 @@ create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2;
show create view vt1;
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
create or replace view vt1 as select * from t1 union select * from t1;
select * from vt1;
a
1
create or replace view vvt1 as select * from t1, t2, vt1;
ERROR HY000: Creating VIEW `vvt1` is prohibited: versioned VIEW `vt1` in query!
drop view vt1, vt12;
......
......@@ -85,6 +85,9 @@ show create view vt1;
create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2;
show create view vt1;
create or replace view vt1 as select * from t1 union select * from t1;
select * from vt1;
--error ER_VERS_VIEW_PROHIBITED
create or replace view vvt1 as select * from t1, t2, vt1;
......
......@@ -17079,6 +17079,10 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
share->row_start_field= sys_trx_start->field_index;
share->row_end_field= sys_trx_end->field_index;
}
else
{
DBUG_ASSERT(!sys_trx_start && !sys_trx_end);
}
DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field));
DBUG_ASSERT(field_count >= (uint) (reg_field - table->field));
......
......@@ -453,10 +453,12 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
goto err;
}
for (SELECT_LEX *sl= select_lex; sl; sl= sl->next_select())
{ /* System Versioning: fix system fields of versioned view */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-extra-args"
// Similar logic as in mysql_derived_prepare()
// Leading versioning table detected implicitly (first one selected)
TABLE_LIST *impli_table= NULL;
// Leading versioning table specified explicitly
......@@ -498,7 +500,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
/* Implicitly add versioning fields if needed */
Item *item;
List_iterator_fast<Item> it(select_lex->item_list);
List_iterator_fast<Item> it(sl->item_list);
DBUG_ASSERT(table->alias);
while ((item= it++))
......@@ -577,9 +579,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
if (impli_table)
{
if (!expli_start && select_lex->vers_push_field(thd, impli_table, impli_start))
if (!expli_start && sl->vers_push_field(thd, impli_table, impli_start))
goto err;
if (!expli_end && select_lex->vers_push_field(thd, impli_table, impli_end))
if (!expli_end && sl->vers_push_field(thd, impli_table, impli_end))
goto err;
}
#pragma GCC diagnostic pop
......
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