Commit 46d572dd authored by Eugene Kosov's avatar Eugene Kosov Committed by Aleksey Midenkov

SQL: default engine fix in create from versioned [fixes #206]

parent faab918e
......@@ -61,6 +61,15 @@ drop table tmp;
end if;
end~~
drop table if exists t1;
create function if not exists non_default_engine()
returns varchar(255)
deterministic
begin
if default_engine() = 'innodb' then
return 'myisam';
end if;
return 'innodb';
end~~
create table t1 (
x1 int unsigned,
Sys_start SYS_TRX_TYPE generated always as row start comment 'start',
......@@ -328,9 +337,18 @@ select st, en from t2 for system_time all where y = 2 into @st, @en;
select y from t2 for system_time all where st = @st and en = @en;
y
2
create or replace table t1 (a int) with system versioning engine INNODB_OR_MYISAM;
create or replace table t2 as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
create or replace table t2 engine INNODB_OR_MYISAM as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
ERROR HY000: `sys_trx_start` must be of type `SYS_TRX_TYPE` for versioned table `t2`
create or replace table t1 (a int, id int) with system versioning engine INNODB_OR_MYISAM;
create or replace table t2 (b int, id int);
create or replace table t3 as
select t2.b, t1.a, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
drop table t1;
drop table t2;
drop table t3;
drop function non_default_engine;
drop procedure verify_vtq;
drop procedure innodb_verify_vtq;
drop function default_engine;
......
......@@ -4,7 +4,21 @@
drop table if exists t1;
--enable_warnings
delimiter ~~;
create function if not exists non_default_engine()
returns varchar(255)
deterministic
begin
if default_engine() = 'innodb' then
return 'myisam';
end if;
return 'innodb';
end~~
delimiter ;~~
--let $sys_datatype= `select sys_datatype()`
--let $default_engine= `select default_engine()`
--let $non_default_engine= `select non_default_engine()`
--replace_result "bigint unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE
eval create table t1 (
......@@ -257,8 +271,23 @@ select y from t2 for system_time all where st = @st and en = @en;
select st, en from t2 for system_time all where y = 2 into @st, @en;
select y from t2 for system_time all where st = @st and en = @en;
--replace_result innodb INNODB_OR_MYISAM myisam INNODB_OR_MYISAM
eval create or replace table t1 (a int) with system versioning engine $non_default_engine;
create or replace table t2 as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
--replace_result innodb INNODB_OR_MYISAM myisam INNODB_OR_MYISAM "BIGINT(20) UNSIGNED" SYS_TRX_TYPE "TIMESTAMP(6)" SYS_TRX_TYPE
--error ER_VERS_FIELD_WRONG_TYPE
eval create or replace table t2 engine $default_engine as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
--replace_result innodb INNODB_OR_MYISAM myisam INNODB_OR_MYISAM
eval create or replace table t1 (a int, id int) with system versioning engine $non_default_engine;
create or replace table t2 (b int, id int);
create or replace table t3 as
select t2.b, t1.a, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
drop table t1;
drop table t2;
drop table t3;
drop function non_default_engine;
-- source suite/versioning/common_finish.inc
......@@ -6663,9 +6663,6 @@ bool Vers_parse_info::check_and_fix_implicit(
HA_CREATE_INFO *create_info,
const char* table_name)
{
bool integer_fields=
create_info->db_type->flags & HTON_NATIVE_SYS_VERSIONING;
SELECT_LEX &slex= thd->lex->select_lex;
int vers_tables= 0;
bool from_select= slex.item_list.elements ? true : false;
......@@ -6677,6 +6674,21 @@ bool Vers_parse_info::check_and_fix_implicit(
if (table->table && table->table->versioned())
vers_tables++;
}
// Possibly override default storage engine to match
// one used in source table.
if (!(create_info->used_fields & HA_CREATE_USED_ENGINE))
{
List_iterator_fast<Create_field> it(alter_info->create_list);
while (Create_field *f= it++)
{
if (is_trx_start(*f) || is_trx_end(*f))
{
create_info->db_type= f->field->orig_table->file->ht;
break;
}
}
}
}
// CREATE ... SELECT: if at least one table in SELECT is versioned,
......@@ -6750,6 +6762,8 @@ bool Vers_parse_info::check_and_fix_implicit(
}
}
bool integer_fields= create_info->db_type->flags & HTON_NATIVE_SYS_VERSIONING;
if (vers_tables > 0)
{
if (!generated_as_row.start && !generated_as_row.end)
......
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