mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
SQL: CREATE VIEW and misc improvements [fixes #183]
This commit is contained in:
@ -436,6 +436,8 @@ x y
|
||||
1 1
|
||||
2 1
|
||||
3 1
|
||||
select * from t1 for system_time all, t2 for system_time all query for system_time all;
|
||||
ERROR HY000: Wrong versioned query: unused `QUERY FOR SYSTEM_TIME` clause!
|
||||
drop view v1;
|
||||
drop table t1, t2;
|
||||
call innodb_verify_vtq(27);
|
||||
|
@ -8,7 +8,7 @@ set @vt1= concat("create view vt1 as select * from t1 for system_time as of time
|
||||
prepare stmt from @vt1;
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
set @vt2= concat("create view vt2 as select * from t1 for system_time as of timestamp '", @t2, "'");
|
||||
set @vt2= concat("create 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;
|
||||
@ -76,10 +76,6 @@ x
|
||||
select * from vt1 for system_time all;
|
||||
x
|
||||
3
|
||||
create view error_view as select *, sys_trx_start from t1;
|
||||
ERROR 42S21: Duplicate column name 'sys_trx_start'
|
||||
create view error_view as select *, sys_trx_end from t1;
|
||||
ERROR 42S21: Duplicate column name 'sys_trx_end'
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
insert into t1 values (1), (2);
|
||||
set @t1=now(6);
|
||||
@ -91,27 +87,14 @@ set @tmp= concat("create or replace view vt1 as select * from t1 for system_time
|
||||
prepare stmt from @tmp;
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
set @tmp= concat("create or replace view vvt1 as select * from vt1 for system_time as of timestamp '", @t2, "'");
|
||||
prepare stmt from @tmp;
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
set @tmp= concat("create or replace view vvvt1 as select * from vvt1 for system_time as of timestamp '", @t3, "'");
|
||||
prepare stmt from @tmp;
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
select * from vt1 for system_time all;
|
||||
x
|
||||
1
|
||||
2
|
||||
select * from vvt1 for system_time all;
|
||||
x
|
||||
1
|
||||
select * from vvvt1 for system_time all;
|
||||
x
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
create or replace view vt1(c) as select x from t1;
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
create or replace table t2 (b int) with system versioning;
|
||||
create or replace table t1 (a 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 t2 values (2);
|
||||
create or replace view vt12 as select * from t1 cross join t2;
|
||||
@ -121,5 +104,24 @@ a b
|
||||
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
|
||||
select * from vt12;
|
||||
a b
|
||||
drop view vt1, vvt1, vvvt1, vt12;
|
||||
drop table 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!
|
||||
create or replace view vt1 as select a, t1.sys_trx_end, t2.sys_trx_end from t1, t2;
|
||||
ERROR HY000: Creating VIEW `vt1` is prohibited: multiple end system fields `t1.sys_trx_end`, `t2.sys_trx_end` in query!
|
||||
create or replace table t3 (x int);
|
||||
create or replace view vt1 as select * from t1, t2, t3;
|
||||
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`.`b` AS `b`,`t3`.`x` AS `x`,`t1`.`sys_trx_start` AS `sys_trx_start`,`t1`.`sys_trx_end` AS `sys_trx_end` from ((`t1` FOR SYSTEM_TIME ALL join `t2` FOR SYSTEM_TIME ALL) join `t3`) where `t1`.`sys_trx_end` = 18446744073709551615 and `t2`.`sys_trx_end` = 18446744073709551615 latin1 latin1_swedish_ci
|
||||
create or replace view vt1 as select * from t3, t2, t1;
|
||||
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 `t3`.`x` AS `x`,`t2`.`b` AS `b`,`t1`.`a` AS `a`,`t2`.`sys_trx_start` AS `sys_trx_start`,`t2`.`sys_trx_end` AS `sys_trx_end` from ((`t3` join `t2` FOR SYSTEM_TIME ALL) join `t1` FOR SYSTEM_TIME ALL) where `t2`.`sys_trx_end` = 18446744073709551615 and `t1`.`sys_trx_end` = 18446744073709551615 latin1 latin1_swedish_ci
|
||||
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 vvt1 as select * from t1, t2, vt1;
|
||||
ERROR HY000: Creating VIEW `vvt1` is prohibited: versioned VIEW `vt1` in query!
|
||||
drop view vt1, vt12;
|
||||
drop table t1, t2, t3;
|
||||
|
@ -197,6 +197,9 @@ delete from t1 where x = 3;
|
||||
insert into t2 values (1);
|
||||
select * from t1, t2 query for system_time all;
|
||||
|
||||
--error ER_VERS_WRONG_QUERY
|
||||
select * from t1 for system_time all, t2 for system_time all query for system_time all;
|
||||
|
||||
drop view v1;
|
||||
drop table t1, t2;
|
||||
|
||||
|
@ -12,7 +12,7 @@ delete from t1;
|
||||
set @vt1= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
|
||||
prepare stmt from @vt1; execute stmt; drop prepare stmt;
|
||||
|
||||
set @vt2= concat("create view vt2 as select * from t1 for system_time as of timestamp '", @t2, "'");
|
||||
set @vt2= concat("create 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;
|
||||
|
||||
select * from vt1 for system_time all;
|
||||
@ -46,11 +46,6 @@ select * from vt1;
|
||||
select * from t1 for system_time all;
|
||||
select * from vt1 for system_time all;
|
||||
|
||||
--error ER_DUP_FIELDNAME
|
||||
create view error_view as select *, sys_trx_start from t1;
|
||||
--error ER_DUP_FIELDNAME
|
||||
create view error_view as select *, sys_trx_end from t1;
|
||||
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
insert into t1 values (1), (2);
|
||||
set @t1=now(6);
|
||||
@ -61,20 +56,14 @@ set @t3=now(6);
|
||||
|
||||
set @tmp= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
|
||||
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
||||
set @tmp= concat("create or replace view vvt1 as select * from vt1 for system_time as of timestamp '", @t2, "'");
|
||||
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
||||
set @tmp= concat("create or replace view vvvt1 as select * from vvt1 for system_time as of timestamp '", @t3, "'");
|
||||
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
||||
|
||||
select * from vt1 for system_time all;
|
||||
select * from vvt1 for system_time all;
|
||||
select * from vvvt1 for system_time all;
|
||||
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
create or replace view vt1(c) as select x from t1;
|
||||
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
create or replace table t2 (b int) with system versioning;
|
||||
create or replace table t1 (a 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 t2 values (2);
|
||||
create or replace view vt12 as select * from t1 cross join t2;
|
||||
@ -82,5 +71,21 @@ select * from vt12;
|
||||
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
|
||||
select * from vt12;
|
||||
|
||||
drop view vt1, vvt1, vvvt1, vt12;
|
||||
drop table t1, t2;
|
||||
--error ER_VERS_VIEW_PROHIBITED
|
||||
create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2;
|
||||
--error ER_VERS_VIEW_PROHIBITED
|
||||
create or replace view vt1 as select a, t1.sys_trx_end, t2.sys_trx_end from t1, t2;
|
||||
|
||||
create or replace table t3 (x int);
|
||||
create or replace view vt1 as select * from t1, t2, t3;
|
||||
show create view vt1;
|
||||
create or replace view vt1 as select * from t3, t2, t1;
|
||||
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;
|
||||
|
||||
--error ER_VERS_VIEW_PROHIBITED
|
||||
create or replace view vvt1 as select * from t1, t2, vt1;
|
||||
|
||||
drop view vt1, vt12;
|
||||
drop table t1, t2, t3;
|
||||
|
@ -7535,5 +7535,14 @@ ER_VERS_NOT_ALLOWED
|
||||
ER_VERS_WRONG_QUERY_TYPE
|
||||
eng "%`s works only with %`s query type"
|
||||
|
||||
ER_VERS_VIEW_PROHIBITED
|
||||
eng "Creating VIEW %`s is prohibited!"
|
||||
|
||||
ER_VERS_WRONG_QUERY
|
||||
eng "Wrong versioned query: %s"
|
||||
|
||||
WARN_VERS_ALIAS_TOO_LONG
|
||||
eng "Auto generated alias for `%s.%s` is too long; using `%s`."
|
||||
|
||||
ER_WRONG_TABLESPACE_NAME 42000
|
||||
eng "Incorrect tablespace name `%-.192s`"
|
||||
|
@ -7582,7 +7582,6 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
|
||||
if (!(item= field_iterator.create_item(thd)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/* This will be deprecated when HIDDEN feature will come to MariaDB. */
|
||||
if (item->type() == Item::FIELD_ITEM)
|
||||
{
|
||||
Item_field *f= static_cast<Item_field *>(item);
|
||||
@ -7597,8 +7596,8 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
|
||||
tl->vers_conditions.type == FOR_SYSTEM_TIME_UNSPECIFIED ?
|
||||
slex->vers_conditions.type : tl->vers_conditions.type;
|
||||
|
||||
if ((sys_field && vers_hide == VERS_HIDE_FULL &&
|
||||
thd->lex->sql_command != SQLCOM_CREATE_TABLE) ||
|
||||
if ((sys_field && (thd->lex->sql_command == SQLCOM_CREATE_VIEW ||
|
||||
vers_hide == VERS_HIDE_FULL && thd->lex->sql_command != SQLCOM_CREATE_TABLE)) ||
|
||||
((fl & HIDDEN_FLAG) && (
|
||||
!sys_field ||
|
||||
vers_hide == VERS_HIDE_IMPLICIT ||
|
||||
|
@ -7044,3 +7044,25 @@ bool LEX::sp_add_cfetch(THD *thd, const LEX_STRING &name)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SELECT_LEX::vers_push_field(THD *thd, TABLE_LIST *table, const char* field_name)
|
||||
{
|
||||
char buf[MAX_FIELD_NAME];
|
||||
Item_field *fld= new (thd->mem_root) Item_field(thd, &context,
|
||||
table->db, table->alias, field_name);
|
||||
if (!fld)
|
||||
return true;
|
||||
|
||||
item_list.push_back(fld);
|
||||
|
||||
if (thd->lex->view_list.elements)
|
||||
{
|
||||
if (LEX_STRING *l= thd->make_lex_string(field_name, strlen(field_name)))
|
||||
thd->lex->view_list.push_back(l);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -991,8 +991,9 @@ public:
|
||||
/* it is for correct printing SELECT options */
|
||||
thr_lock_type lock_type;
|
||||
|
||||
/* System Versioning conditions */
|
||||
/* System Versioning */
|
||||
vers_select_conds_t vers_conditions;
|
||||
bool vers_push_field(THD *thd, TABLE_LIST *table, const char* field_name);
|
||||
|
||||
void init_query();
|
||||
void init_select();
|
||||
|
@ -694,6 +694,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
|
||||
TABLE_LIST *table;
|
||||
int versioned_tables= 0;
|
||||
int slex_conds_used= 0;
|
||||
Query_arena *arena= 0, backup;
|
||||
|
||||
if (!thd->stmt_arena->is_conventional() &&
|
||||
@ -707,7 +708,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
{
|
||||
if (table->table && table->table->versioned())
|
||||
versioned_tables++;
|
||||
else if (table->vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||
else if (table->vers_conditions)
|
||||
{
|
||||
my_error(ER_VERSIONING_REQUIRED, MYF(0), "`FOR SYSTEM_TIME` query");
|
||||
DBUG_RETURN(-1);
|
||||
@ -716,7 +717,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
|
||||
if (versioned_tables == 0)
|
||||
{
|
||||
if (slex->vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||
if (slex->vers_conditions)
|
||||
{
|
||||
my_error(ER_VERSIONING_REQUIRED, MYF(0), "`FOR SYSTEM_TIME` query");
|
||||
DBUG_RETURN(-1);
|
||||
@ -775,17 +776,17 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
{
|
||||
if (table->table && table->table->versioned())
|
||||
{
|
||||
vers_select_conds_t &vers_conditions=
|
||||
table->vers_conditions.type == FOR_SYSTEM_TIME_UNSPECIFIED ?
|
||||
slex->vers_conditions : table->vers_conditions;
|
||||
vers_select_conds_t &vers_conditions= !table->vers_conditions?
|
||||
(++slex_conds_used, slex->vers_conditions) :
|
||||
table->vers_conditions;
|
||||
|
||||
if (vers_conditions.type == FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||
if (!vers_conditions)
|
||||
{
|
||||
if (vers_conditions.init_from_sysvar(thd))
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
if (vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||
if (vers_conditions)
|
||||
{
|
||||
switch (slex->lock_type)
|
||||
{
|
||||
@ -804,9 +805,9 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
break;
|
||||
}
|
||||
|
||||
if (vers_conditions.type == FOR_SYSTEM_TIME_ALL)
|
||||
if (vers_conditions == FOR_SYSTEM_TIME_ALL)
|
||||
continue;
|
||||
}
|
||||
} // if (vers_conditions)
|
||||
|
||||
COND** dst_cond= where_expr;
|
||||
if (table->on_expr)
|
||||
@ -979,6 +980,12 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
|
||||
if (!slex_conds_used && slex->vers_conditions)
|
||||
{
|
||||
my_error(ER_VERS_WRONG_QUERY, MYF(0), "unused `QUERY FOR SYSTEM_TIME` clause!");
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
DBUG_RETURN(0);
|
||||
#undef newx
|
||||
}
|
||||
@ -16985,8 +16992,8 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
|
||||
sys_trx_end->flags|= VERS_SYS_END_FLAG | HIDDEN_FLAG;
|
||||
share->versioned= true;
|
||||
share->field= table->field;
|
||||
share->row_start_field= field_count - 2;
|
||||
share->row_end_field= field_count - 1;
|
||||
share->row_start_field= sys_trx_start->field_index;
|
||||
share->row_end_field= sys_trx_end->field_index;
|
||||
}
|
||||
|
||||
DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field));
|
||||
|
137
sql/sql_view.cc
137
sql/sql_view.cc
@ -453,38 +453,125 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
|
||||
goto err;
|
||||
}
|
||||
|
||||
{ /* System Versioning begin */
|
||||
TABLE_LIST *impli_table= NULL, *expli_table= NULL;
|
||||
const char *impli_start, *impli_end;
|
||||
Item_field *expli_start= NULL, *expli_end= NULL;
|
||||
|
||||
for (TABLE_LIST *table= tables; table; table= table->next_local)
|
||||
{
|
||||
DBUG_ASSERT(!table->is_view() || table->view);
|
||||
|
||||
// Any versioned table in VIEW will add `FOR SYSTEM_TIME ALL` + WHERE:
|
||||
// if there are at least one versioned table then VIEW will contain FOR_SYSTEM_TIME_ALL
|
||||
// (because it is in fact LEX used to parse its SELECT).
|
||||
if (table->is_view() && table->view->vers_conditions == FOR_SYSTEM_TIME_ALL)
|
||||
{
|
||||
my_printf_error(
|
||||
ER_VERS_VIEW_PROHIBITED,
|
||||
"Creating VIEW %`s is prohibited: versioned VIEW %`s in query!", MYF(0),
|
||||
view->table_name,
|
||||
table->table_name);
|
||||
res= true;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!table->table || !table->table->versioned())
|
||||
continue;
|
||||
|
||||
const char *table_start= table->table->vers_start_field()->field_name;
|
||||
const char *table_end= table->table->vers_end_field()->field_name;
|
||||
|
||||
if (!impli_table)
|
||||
{
|
||||
impli_table= table;
|
||||
impli_start= table_start;
|
||||
impli_end= table_end;
|
||||
}
|
||||
|
||||
/* Implicitly add versioning fields if needed */
|
||||
{
|
||||
TABLE_LIST *tl = tables;
|
||||
while (tl && tl->is_view())
|
||||
tl = tl->view->select_lex.table_list.first;
|
||||
if (tl && tl->table)
|
||||
{
|
||||
TABLE_SHARE *s= tl->table->s;
|
||||
if (s->versioned)
|
||||
{
|
||||
const char *start= s->vers_start_field()->field_name;
|
||||
const char *end = s->vers_end_field()->field_name;
|
||||
Item *item;
|
||||
List_iterator_fast<Item> it(select_lex->item_list);
|
||||
|
||||
select_lex->item_list.push_back(new (thd->mem_root) Item_field(
|
||||
thd, &select_lex->context, tables->db, tables->alias, start));
|
||||
select_lex->item_list.push_back(new (thd->mem_root) Item_field(
|
||||
thd, &select_lex->context, tables->db, tables->alias, end));
|
||||
|
||||
if (lex->view_list.elements)
|
||||
DBUG_ASSERT(table->alias);
|
||||
while ((item= it++))
|
||||
{
|
||||
if (LEX_STRING *s= thd->make_lex_string(start, strlen(start)))
|
||||
lex->view_list.push_back(s);
|
||||
else
|
||||
if (item->real_item()->type() != Item::FIELD_ITEM)
|
||||
continue;
|
||||
Item_field *fld= (Item_field*) (item->real_item());
|
||||
if (fld->table_name && 0 != my_strcasecmp(table_alias_charset, table->alias, fld->table_name))
|
||||
continue;
|
||||
DBUG_ASSERT(fld->field_name);
|
||||
if (0 == my_strcasecmp(system_charset_info, table_start, fld->field_name))
|
||||
{
|
||||
if (expli_start)
|
||||
{
|
||||
my_printf_error(
|
||||
ER_VERS_VIEW_PROHIBITED,
|
||||
"Creating VIEW %`s is prohibited: multiple start system fields `%s.%s`, `%s.%s` in query!", MYF(0),
|
||||
view->table_name,
|
||||
expli_table->alias,
|
||||
expli_start->field_name,
|
||||
table->alias,
|
||||
fld->field_name);
|
||||
res= true;
|
||||
goto err;
|
||||
if (LEX_STRING *s= thd->make_lex_string(end, strlen(end)))
|
||||
lex->view_list.push_back(s);
|
||||
else
|
||||
}
|
||||
if (expli_table)
|
||||
{
|
||||
if (expli_table != table)
|
||||
{
|
||||
expli_table_err:
|
||||
my_printf_error(
|
||||
ER_VERS_VIEW_PROHIBITED,
|
||||
"Creating VIEW %`s is prohibited: system fields from multiple tables %`s, %`s in query!", MYF(0),
|
||||
view->table_name,
|
||||
expli_table->alias,
|
||||
table->alias);
|
||||
res= true;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
expli_table= table;
|
||||
expli_start= fld;
|
||||
impli_end= table_end;
|
||||
}
|
||||
else if (0 == my_strcasecmp(system_charset_info, table_end, fld->field_name))
|
||||
{
|
||||
if (expli_end)
|
||||
{
|
||||
my_printf_error(
|
||||
ER_VERS_VIEW_PROHIBITED,
|
||||
"Creating VIEW %`s is prohibited: multiple end system fields `%s.%s`, `%s.%s` in query!", MYF(0),
|
||||
view->table_name,
|
||||
expli_table->alias,
|
||||
expli_end->field_name,
|
||||
table->alias,
|
||||
fld->field_name);
|
||||
res= true;
|
||||
goto err;
|
||||
}
|
||||
if (expli_table)
|
||||
{
|
||||
if (expli_table != table)
|
||||
goto expli_table_err;
|
||||
}
|
||||
else
|
||||
expli_table= table;
|
||||
expli_end= fld;
|
||||
impli_start= table_start;
|
||||
}
|
||||
} // while ((item= it++))
|
||||
} // for (TABLE_LIST *table)
|
||||
|
||||
if (expli_table)
|
||||
impli_table= expli_table;
|
||||
if (!expli_start && select_lex->vers_push_field(thd, impli_table, impli_start))
|
||||
goto err;
|
||||
if (!expli_end && select_lex->vers_push_field(thd, impli_table, impli_end))
|
||||
goto err;
|
||||
} /* System Versioning end */
|
||||
|
||||
view= lex->unlink_first_table(&link_to_local);
|
||||
|
||||
@ -2071,8 +2158,8 @@ bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view)
|
||||
{
|
||||
TABLE_SHARE *s= fld->context->table_list->table->s;
|
||||
if (s->versioned &&
|
||||
(!strcmp(fld->name, s->vers_start_field()->field_name) ||
|
||||
!strcmp(fld->name, s->vers_end_field()->field_name)))
|
||||
(!strcmp(fld->field_name, s->vers_start_field()->field_name) ||
|
||||
!strcmp(fld->field_name, s->vers_end_field()->field_name)))
|
||||
continue;
|
||||
list->push_back(fld, thd->mem_root);
|
||||
}
|
||||
|
22
sql/table.h
22
sql/table.h
@ -1512,31 +1512,32 @@ public:
|
||||
|
||||
bool versioned() const
|
||||
{
|
||||
DBUG_ASSERT(s);
|
||||
return s->versioned;
|
||||
}
|
||||
|
||||
/* Versioned by SQL layer */
|
||||
bool versioned_by_sql() const
|
||||
{
|
||||
DBUG_ASSERT(file);
|
||||
DBUG_ASSERT(s && file);
|
||||
return s->versioned && !file->versioned();
|
||||
}
|
||||
|
||||
bool versioned_by_engine() const
|
||||
{
|
||||
DBUG_ASSERT(file);
|
||||
DBUG_ASSERT(s && file);
|
||||
return s->versioned && file->versioned();
|
||||
}
|
||||
|
||||
Field *vers_start_field() const
|
||||
{
|
||||
DBUG_ASSERT(s->versioned);
|
||||
DBUG_ASSERT(s && s->versioned);
|
||||
return field[s->row_start_field];
|
||||
}
|
||||
|
||||
Field *vers_end_field() const
|
||||
{
|
||||
DBUG_ASSERT(s->versioned);
|
||||
DBUG_ASSERT(s && s->versioned);
|
||||
return field[s->row_end_field];
|
||||
}
|
||||
|
||||
@ -1874,6 +1875,19 @@ struct vers_select_conds_t
|
||||
}
|
||||
|
||||
bool init_from_sysvar(THD *thd);
|
||||
|
||||
bool operator== (vers_range_type_t b)
|
||||
{
|
||||
return type == b;
|
||||
}
|
||||
bool operator!= (vers_range_type_t b)
|
||||
{
|
||||
return type != b;
|
||||
}
|
||||
operator bool()
|
||||
{
|
||||
return type != FOR_SYSTEM_TIME_UNSPECIFIED;
|
||||
}
|
||||
};
|
||||
|
||||
struct LEX;
|
||||
|
Reference in New Issue
Block a user