Skip to content

Commit

Permalink
SQL: ignore columns WITHOUT VERSIONING [fixes #220]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs committed Jul 4, 2017
1 parent bdcce58 commit 1903b40
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
2 changes: 0 additions & 2 deletions mysql-test/suite/versioning/r/create.result
Expand Up @@ -211,7 +211,6 @@ create or replace table t1 (
A3 int,
B int without system versioning
);
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 (
A4 int,
B int without system versioning
Expand Down Expand Up @@ -254,7 +253,6 @@ t1 CREATE TABLE `t1` (
create or replace table t1 (
A7 int without system versioning
);
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 (
A8 int without system versioning
) with system versioning;
Expand Down
2 changes: 0 additions & 2 deletions mysql-test/suite/versioning/t/create.test
Expand Up @@ -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
show create table t1;

--error ER_VERS_WRONG_PARAMS
create or replace table t1 (
A3 int,
B int without system versioning
Expand All @@ -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
show create table t1;

--error ER_VERS_WRONG_PARAMS
create or replace table t1 (
A7 int without system versioning
);
Expand Down
54 changes: 30 additions & 24 deletions sql/handler.cc
Expand Up @@ -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
{
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
{
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
{
Expand Down Expand Up @@ -6638,17 +6638,16 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info,
bool integer_fields)
{
// If user specified some of these he must specify the others too. Do nothing.
if (generated_as_row.start || generated_as_row.end ||
period_for_system_time.start || period_for_system_time.end)
if (as_row.start || as_row.end || system_time.start || system_time.end)
return false;

alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;

static const LString sys_trx_start= "sys_trx_start";
static const LString sys_trx_end= "sys_trx_end";

period_for_system_time= start_end_t(sys_trx_start, sys_trx_end);
generated_as_row= period_for_system_time;
system_time= start_end_t(sys_trx_start, sys_trx_end);
as_row= system_time;

return vers_create_sys_field(thd, sys_trx_start, alter_info,
VERS_SYS_START_FLAG,
Expand Down Expand Up @@ -6703,14 +6702,22 @@ bool Vers_parse_info::check_and_fix_implicit(
if (!need_check())
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)
{
my_error_as(ER_VERS_WRONG_PARAMS, ER_NOT_ALLOWED, MYF(0), table_name,
"WITHOUT SYSTEM VERSIONING");
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,
"WITH SYSTEM VERSIONING");
Expand All @@ -6723,7 +6730,7 @@ bool Vers_parse_info::check_and_fix_implicit(
{
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);
if (orig_table && orig_table != f->field->orig_table)
Expand All @@ -6733,23 +6740,23 @@ bool Vers_parse_info::check_and_fix_implicit(
return true;
}
orig_table= f->field->orig_table;
generated_as_row.start= f->field_name;
period_for_system_time.start= generated_as_row.start;
as_row.start= f->field_name;
system_time.start= as_row.start;
}
continue;
}
if (is_trx_end(*f))
{
if (!generated_as_row.end)
if (!as_row.end)
{
DBUG_ASSERT(vers_tables > 0);
if (orig_table && orig_table != f->field->orig_table)
{
goto err_different_tables;
}
orig_table= f->field->orig_table;
generated_as_row.end= f->field_name;
period_for_system_time.end= generated_as_row.end;
as_row.end= f->field_name;
system_time.end= as_row.end;
}
continue;
}
Expand Down Expand Up @@ -6782,8 +6789,7 @@ bool Vers_parse_info::check_and_fix_implicit(
}

bool table_with_system_versioning=
generated_as_row.start || generated_as_row.end ||
period_for_system_time.start || period_for_system_time.end;
as_row.start || as_row.end || system_time.start || system_time.end;

if (!thd->lex->tmp_table() &&
// CREATE from SELECT (Create_fields are not yet added)
Expand Down Expand Up @@ -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;
DBUG_ASSERT(start && end);

generated_as_row= start_end_t(start, end);
period_for_system_time= generated_as_row;
as_row= start_end_t(start, end);
system_time= as_row;

if (alter_info->create_list.elements)
{
Expand Down Expand Up @@ -6945,8 +6951,8 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
return true;
}

generated_as_row= start_end_t(f_start->field_name, f_end->field_name);
period_for_system_time= generated_as_row;
as_row= start_end_t(f_start->field_name, f_end->field_name);
system_time= as_row;

create_info->options|= HA_VERSIONED_TABLE;
return false;
Expand All @@ -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
{
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,
generated_as_row.start ? "AS ROW END" : "AS ROW START");
as_row.start ? "AS ROW END" : "AS ROW START");
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,
"PERIOD FOR SYSTEM_TIME");
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,
"PERIOD FOR SYSTEM_TIME", "AS ROW START");
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,
"PERIOD FOR SYSTEM_TIME", "AS ROW END");
Expand Down
16 changes: 8 additions & 8 deletions sql/handler.h
Expand Up @@ -1694,13 +1694,13 @@ struct Vers_parse_info
LString_i end;
};

start_end_t period_for_system_time;
start_end_t generated_as_row;
start_end_t system_time;
start_end_t as_row;

void set_period_for_system_time(LString start, LString end)
{
period_for_system_time.start = start;
period_for_system_time.end = end;
system_time.start = start;
system_time.end = end;
}

private:
Expand All @@ -1716,10 +1716,10 @@ struct Vers_parse_info
unversioned_fields ||
with_system_versioning ||
without_system_versioning ||
period_for_system_time.start.str ||
period_for_system_time.end.str ||
generated_as_row.start.str ||
generated_as_row.end.str;
system_time.start ||
system_time.end ||
as_row.start ||
as_row.end;
}
bool check_with_conditions(const char *table_name) const;
bool check_generated_type(const char *table_name, Alter_info *alter_info,
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_table.cc
Expand Up @@ -4326,9 +4326,9 @@ vers_prepare_keys(THD *thd,
{
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);
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);

List_iterator<Key> key_it(alter_info->key_list);
Expand All @@ -4355,7 +4355,7 @@ vers_prepare_keys(THD *thd,
continue; // Key already contains Sys_start or Sys_end

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);
}

Expand Down
4 changes: 2 additions & 2 deletions sql/sql_yacc.yy
Expand Up @@ -6305,12 +6305,12 @@ field_def:
switch ($4)
{
case 1:
p= &info.generated_as_row.start;
p= &info.as_row.start;
clause= "AS ROW START";
lex->last_field->flags|= VERS_SYS_START_FLAG;
break;
case 0:
p= &info.generated_as_row.end;
p= &info.as_row.end;
clause= "AS ROW END";
lex->last_field->flags|= VERS_SYS_END_FLAG;
break;
Expand Down
6 changes: 2 additions & 4 deletions sql/unireg.cc
Expand Up @@ -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);
Create_field *sql_field = NULL;

const char *row_field =
row_start ?
create_info->vers_info.generated_as_row.start :
create_info->vers_info.generated_as_row.end;
const char *row_field= row_start ? create_info->vers_info.as_row.start
: create_info->vers_info.as_row.end;
DBUG_ASSERT(row_field);

for (unsigned field_no = 0; (sql_field = it++); ++field_no)
Expand Down

0 comments on commit 1903b40

Please sign in to comment.