Commit 1903b407 authored by Eugene Kosov's avatar Eugene Kosov Committed by GitHub

SQL: ignore columns WITHOUT VERSIONING [fixes #220]

parent bdcce58f
...@@ -211,7 +211,6 @@ create or replace table t1 ( ...@@ -211,7 +211,6 @@ create or replace table t1 (
A3 int, A3 int,
B int without system versioning B int without system versioning
); );
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 ( create or replace table t1 (
A4 int, A4 int,
B int without system versioning B int without system versioning
...@@ -254,7 +253,6 @@ t1 CREATE TABLE `t1` ( ...@@ -254,7 +253,6 @@ t1 CREATE TABLE `t1` (
create or replace table t1 ( create or replace table t1 (
A7 int without system versioning A7 int without system versioning
); );
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 ( create or replace table t1 (
A8 int without system versioning A8 int without system versioning
) with system versioning; ) with system versioning;
......
...@@ -157,7 +157,6 @@ create or replace table t1 ( ...@@ -157,7 +157,6 @@ create or replace table t1 (
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM "bigint(20) unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE --replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM "bigint(20) unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE
show create table t1; show create table t1;
--error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
A3 int, A3 int,
B int without system versioning B int without system versioning
...@@ -184,7 +183,6 @@ create or replace table t1 ( ...@@ -184,7 +183,6 @@ create or replace table t1 (
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM "bigint(20) unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE --replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM "bigint(20) unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE
show create table t1; show create table t1;
--error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
A7 int without system versioning A7 int without system versioning
); );
......
...@@ -6584,12 +6584,12 @@ int del_global_index_stat(THD *thd, TABLE* table, KEY* key_info) ...@@ -6584,12 +6584,12 @@ int del_global_index_stat(THD *thd, TABLE* table, KEY* key_info)
bool Vers_parse_info::is_trx_start(const char *name) const bool Vers_parse_info::is_trx_start(const char *name) const
{ {
DBUG_ASSERT(name); DBUG_ASSERT(name);
return generated_as_row.start && generated_as_row.start == LString_i(name); return as_row.start && as_row.start == LString_i(name);
} }
bool Vers_parse_info::is_trx_end(const char *name) const bool Vers_parse_info::is_trx_end(const char *name) const
{ {
DBUG_ASSERT(name); DBUG_ASSERT(name);
return generated_as_row.end && generated_as_row.end == LString_i(name); return as_row.end && as_row.end == LString_i(name);
} }
bool Vers_parse_info::is_trx_start(const Create_field &f) const bool Vers_parse_info::is_trx_start(const Create_field &f) const
{ {
...@@ -6638,8 +6638,7 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info, ...@@ -6638,8 +6638,7 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info,
bool integer_fields) bool integer_fields)
{ {
// If user specified some of these he must specify the others too. Do nothing. // If user specified some of these he must specify the others too. Do nothing.
if (generated_as_row.start || generated_as_row.end || if (as_row.start || as_row.end || system_time.start || system_time.end)
period_for_system_time.start || period_for_system_time.end)
return false; return false;
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN; alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
...@@ -6647,8 +6646,8 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info, ...@@ -6647,8 +6646,8 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info,
static const LString sys_trx_start= "sys_trx_start"; static const LString sys_trx_start= "sys_trx_start";
static const LString sys_trx_end= "sys_trx_end"; static const LString sys_trx_end= "sys_trx_end";
period_for_system_time= start_end_t(sys_trx_start, sys_trx_end); system_time= start_end_t(sys_trx_start, sys_trx_end);
generated_as_row= period_for_system_time; as_row= system_time;
return vers_create_sys_field(thd, sys_trx_start, alter_info, return vers_create_sys_field(thd, sys_trx_start, alter_info,
VERS_SYS_START_FLAG, VERS_SYS_START_FLAG,
...@@ -6703,6 +6702,13 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6703,6 +6702,13 @@ bool Vers_parse_info::check_and_fix_implicit(
if (!need_check()) if (!need_check())
return false; return false;
if (!versioned_fields && unversioned_fields && !with_system_versioning)
{
// All is correct but this table is not versioned.
create_info->options&= ~HA_VERSIONED_TABLE;
return false;
}
if (without_system_versioning) if (without_system_versioning)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_NOT_ALLOWED, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_NOT_ALLOWED, MYF(0), table_name,
...@@ -6710,7 +6716,8 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6710,7 +6716,8 @@ bool Vers_parse_info::check_and_fix_implicit(
return true; return true;
} }
if (!with_system_versioning && !versioned_fields) if ((system_time.start || system_time.end || as_row.start || as_row.end) &&
!with_system_versioning)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name,
"WITH SYSTEM VERSIONING"); "WITH SYSTEM VERSIONING");
...@@ -6723,7 +6730,7 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6723,7 +6730,7 @@ bool Vers_parse_info::check_and_fix_implicit(
{ {
if (is_trx_start(*f)) if (is_trx_start(*f))
{ {
if (!generated_as_row.start) // not inited in CREATE ... SELECT if (!as_row.start) // not inited in CREATE ... SELECT
{ {
DBUG_ASSERT(vers_tables > 0); DBUG_ASSERT(vers_tables > 0);
if (orig_table && orig_table != f->field->orig_table) if (orig_table && orig_table != f->field->orig_table)
...@@ -6733,14 +6740,14 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6733,14 +6740,14 @@ bool Vers_parse_info::check_and_fix_implicit(
return true; return true;
} }
orig_table= f->field->orig_table; orig_table= f->field->orig_table;
generated_as_row.start= f->field_name; as_row.start= f->field_name;
period_for_system_time.start= generated_as_row.start; system_time.start= as_row.start;
} }
continue; continue;
} }
if (is_trx_end(*f)) if (is_trx_end(*f))
{ {
if (!generated_as_row.end) if (!as_row.end)
{ {
DBUG_ASSERT(vers_tables > 0); DBUG_ASSERT(vers_tables > 0);
if (orig_table && orig_table != f->field->orig_table) if (orig_table && orig_table != f->field->orig_table)
...@@ -6748,8 +6755,8 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6748,8 +6755,8 @@ bool Vers_parse_info::check_and_fix_implicit(
goto err_different_tables; goto err_different_tables;
} }
orig_table= f->field->orig_table; orig_table= f->field->orig_table;
generated_as_row.end= f->field_name; as_row.end= f->field_name;
period_for_system_time.end= generated_as_row.end; system_time.end= as_row.end;
} }
continue; continue;
} }
...@@ -6782,8 +6789,7 @@ bool Vers_parse_info::check_and_fix_implicit( ...@@ -6782,8 +6789,7 @@ bool Vers_parse_info::check_and_fix_implicit(
} }
bool table_with_system_versioning= bool table_with_system_versioning=
generated_as_row.start || generated_as_row.end || as_row.start || as_row.end || system_time.start || system_time.end;
period_for_system_time.start || period_for_system_time.end;
if (!thd->lex->tmp_table() && if (!thd->lex->tmp_table() &&
// CREATE from SELECT (Create_fields are not yet added) // CREATE from SELECT (Create_fields are not yet added)
...@@ -6853,8 +6859,8 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info, ...@@ -6853,8 +6859,8 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
const char *end= share->vers_end_field()->field_name; const char *end= share->vers_end_field()->field_name;
DBUG_ASSERT(start && end); DBUG_ASSERT(start && end);
generated_as_row= start_end_t(start, end); as_row= start_end_t(start, end);
period_for_system_time= generated_as_row; system_time= as_row;
if (alter_info->create_list.elements) if (alter_info->create_list.elements)
{ {
...@@ -6945,8 +6951,8 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info, ...@@ -6945,8 +6951,8 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
return true; return true;
} }
generated_as_row= start_end_t(f_start->field_name, f_end->field_name); as_row= start_end_t(f_start->field_name, f_end->field_name);
period_for_system_time= generated_as_row; system_time= as_row;
create_info->options|= HA_VERSIONED_TABLE; create_info->options|= HA_VERSIONED_TABLE;
return false; return false;
...@@ -6955,28 +6961,28 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info, ...@@ -6955,28 +6961,28 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
bool Vers_parse_info::check_with_conditions(const char *table_name) const bool Vers_parse_info::check_with_conditions(const char *table_name) const
{ {
if (!generated_as_row.start || !generated_as_row.end) if (!as_row.start || !as_row.end)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name,
generated_as_row.start ? "AS ROW END" : "AS ROW START"); as_row.start ? "AS ROW END" : "AS ROW START");
return true; return true;
} }
if (!period_for_system_time.start || !period_for_system_time.end) if (!system_time.start || !system_time.end)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table_name,
"PERIOD FOR SYSTEM_TIME"); "PERIOD FOR SYSTEM_TIME");
return true; return true;
} }
if (generated_as_row.start != period_for_system_time.start) if (as_row.start != system_time.start)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISMATCH, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_MISMATCH, MYF(0), table_name,
"PERIOD FOR SYSTEM_TIME", "AS ROW START"); "PERIOD FOR SYSTEM_TIME", "AS ROW START");
return true; return true;
} }
if (generated_as_row.end != period_for_system_time.end) if (as_row.end != system_time.end)
{ {
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISMATCH, MYF(0), table_name, my_error_as(ER_VERS_WRONG_PARAMS, ER_MISMATCH, MYF(0), table_name,
"PERIOD FOR SYSTEM_TIME", "AS ROW END"); "PERIOD FOR SYSTEM_TIME", "AS ROW END");
......
...@@ -1694,13 +1694,13 @@ struct Vers_parse_info ...@@ -1694,13 +1694,13 @@ struct Vers_parse_info
LString_i end; LString_i end;
}; };
start_end_t period_for_system_time; start_end_t system_time;
start_end_t generated_as_row; start_end_t as_row;
void set_period_for_system_time(LString start, LString end) void set_period_for_system_time(LString start, LString end)
{ {
period_for_system_time.start = start; system_time.start = start;
period_for_system_time.end = end; system_time.end = end;
} }
private: private:
...@@ -1716,10 +1716,10 @@ struct Vers_parse_info ...@@ -1716,10 +1716,10 @@ struct Vers_parse_info
unversioned_fields || unversioned_fields ||
with_system_versioning || with_system_versioning ||
without_system_versioning || without_system_versioning ||
period_for_system_time.start.str || system_time.start ||
period_for_system_time.end.str || system_time.end ||
generated_as_row.start.str || as_row.start ||
generated_as_row.end.str; as_row.end;
} }
bool check_with_conditions(const char *table_name) const; bool check_with_conditions(const char *table_name) const;
bool check_generated_type(const char *table_name, Alter_info *alter_info, bool check_generated_type(const char *table_name, Alter_info *alter_info,
......
...@@ -4326,9 +4326,9 @@ vers_prepare_keys(THD *thd, ...@@ -4326,9 +4326,9 @@ vers_prepare_keys(THD *thd,
{ {
DBUG_ASSERT(create_info->versioned()); DBUG_ASSERT(create_info->versioned());
const char *row_start_field= create_info->vers_info.generated_as_row.start; const char *row_start_field= create_info->vers_info.as_row.start;
DBUG_ASSERT(row_start_field); DBUG_ASSERT(row_start_field);
const char *row_end_field= create_info->vers_info.generated_as_row.end; const char *row_end_field= create_info->vers_info.as_row.end;
DBUG_ASSERT(row_end_field); DBUG_ASSERT(row_end_field);
List_iterator<Key> key_it(alter_info->key_list); List_iterator<Key> key_it(alter_info->key_list);
...@@ -4355,7 +4355,7 @@ vers_prepare_keys(THD *thd, ...@@ -4355,7 +4355,7 @@ vers_prepare_keys(THD *thd,
continue; // Key already contains Sys_start or Sys_end continue; // Key already contains Sys_start or Sys_end
Key_part_spec *key_part_sys_end_col= Key_part_spec *key_part_sys_end_col=
new(thd->mem_root) Key_part_spec(create_info->vers_info.generated_as_row.end, 0); new (thd->mem_root) Key_part_spec(create_info->vers_info.as_row.end, 0);
key->columns.push_back(key_part_sys_end_col); key->columns.push_back(key_part_sys_end_col);
} }
......
...@@ -6305,12 +6305,12 @@ field_def: ...@@ -6305,12 +6305,12 @@ field_def:
switch ($4) switch ($4)
{ {
case 1: case 1:
p= &info.generated_as_row.start; p= &info.as_row.start;
clause= "AS ROW START"; clause= "AS ROW START";
lex->last_field->flags|= VERS_SYS_START_FLAG; lex->last_field->flags|= VERS_SYS_START_FLAG;
break; break;
case 0: case 0:
p= &info.generated_as_row.end; p= &info.as_row.end;
clause= "AS ROW END"; clause= "AS ROW END";
lex->last_field->flags|= VERS_SYS_END_FLAG; lex->last_field->flags|= VERS_SYS_END_FLAG;
break; break;
......
...@@ -99,10 +99,8 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b ...@@ -99,10 +99,8 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b
List_iterator<Create_field> it(create_fields); List_iterator<Create_field> it(create_fields);
Create_field *sql_field = NULL; Create_field *sql_field = NULL;
const char *row_field = const char *row_field= row_start ? create_info->vers_info.as_row.start
row_start ? : create_info->vers_info.as_row.end;
create_info->vers_info.generated_as_row.start :
create_info->vers_info.generated_as_row.end;
DBUG_ASSERT(row_field); DBUG_ASSERT(row_field);
for (unsigned field_no = 0; (sql_field = it++); ++field_no) for (unsigned field_no = 0; (sql_field = it++); ++field_no)
......
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