Commit 303d72a0 authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: redundant error codes reduced

Replaced codes:

ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE
ER_MISSING_WITH_SYSTEM_VERSIONING
ER_SYS_START_NOT_SPECIFIED
ER_SYS_END_NOT_SPECIFIED
ER_MISSING_PERIOD_FOR_SYSTEM_TIME
ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_START_COLUMN
ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_END_COLUMN
ER_SYS_START_AND_SYS_END_SAME
ER_SYS_START_MORE_THAN_ONCE
ER_SYS_END_MORE_THAN_ONCE

with:

ER_VERS_WRONG_PARAMS
ER_VERS_FIELD_WRONG_TYPE
parent 52a68125
...@@ -32,14 +32,14 @@ Sys_start2 timestamp(6) generated always as row start, ...@@ -32,14 +32,14 @@ Sys_start2 timestamp(6) generated always as row start,
Sys_end timestamp(6) generated always as row end, Sys_end timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: 'Generated as row start' specified more than once ERROR HY000: Wrong parameters for versioned table `t1`: multiple 'GENERATED ALWAYS AS ROW START'
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end2 timestamp(6) generated always as row end, Sys_end2 timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: Second column in 'period for system time' must be equal to 'generated as row end' column ERROR HY000: Wrong parameters for versioned table `t1`: 'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW END' mismatch
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -47,12 +47,12 @@ Sys_end timestamp(6) generated always as row end, ...@@ -47,12 +47,12 @@ Sys_end timestamp(6) generated always as row end,
Sys_end2 timestamp(6) generated always as row end, Sys_end2 timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: Generated as row end specified more than once ERROR HY000: Wrong parameters for versioned table `t1`: multiple 'GENERATED ALWAYS AS ROW END'
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: 'Generated as row start' not specified ERROR HY000: Wrong parameters for versioned table `t1`: 'GENERATED AS ROW START' column missing
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -60,63 +60,63 @@ Sys_end timestamp(6) generated always as row end, ...@@ -60,63 +60,63 @@ Sys_end timestamp(6) generated always as row end,
Sys_end2 timestamp(6) generated always as row end, Sys_end2 timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
); );
ERROR HY000: Generated as row end specified more than once ERROR HY000: Wrong parameters for versioned table `t1`: multiple 'GENERATED ALWAYS AS ROW END'
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end timestamp(6) generated always as row end, Sys_end timestamp(6) generated always as row end,
period for system_time (sys_insert, sys_remove) period for system_time (sys_insert, sys_remove)
) with system versioning; ) with system versioning;
ERROR HY000: First column in 'period for system time' must be equal to 'generated as row start' column ERROR HY000: Wrong parameters for versioned table `t1`: 'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW START' mismatch
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end timestamp(6) generated always as row end, Sys_end timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
); );
ERROR HY000: 'With system versioning' is missing ERROR HY000: Wrong parameters for versioned table `t1`: 'WITH SYSTEM VERSIONING' missing
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end timestamp(6) generated always as row end, Sys_end timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_start) period for system_time (Sys_start, Sys_start)
); );
ERROR HY000: 'Period for system_time' must contain two different columns ERROR HY000: Wrong parameters for versioned table `t1`: 'PERIOD FOR SYSTEM_TIME' columns must be different
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start int generated always as row start, Sys_start int generated always as row start,
Sys_end timestamp(6) generated always as row end, Sys_end timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: System start field must be of type TIMESTAMP ERROR HY000: `Sys_start` must be of type `TIMESTAMP` for versioned table `t1`
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end int generated always as row end, Sys_end int generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
ERROR HY000: System end field must be of type TIMESTAMP ERROR HY000: `Sys_end` must be of type `TIMESTAMP` for versioned table `t1`
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
Sys_end bigint generated always as row end, Sys_end bigint generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb; ) with system versioning engine innodb;
ERROR HY000: System start field must be of type BIGINT UNSIGNED ERROR HY000: `Sys_start` must be of type `BIGINT UNSIGNED` for versioned table `t1`
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start bigint generated always as row start, Sys_start bigint generated always as row start,
Sys_end bigint generated always as row end, Sys_end bigint generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb; ) with system versioning engine innodb;
ERROR HY000: System start field must be of type BIGINT UNSIGNED ERROR HY000: `Sys_start` must be of type `BIGINT UNSIGNED` for versioned table `t1`
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start bigint unsigned generated always as row start, Sys_start bigint unsigned generated always as row start,
Sys_end bigint generated always as row end, Sys_end bigint generated always as row end,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb; ) with system versioning engine innodb;
ERROR HY000: System end field must be of type BIGINT UNSIGNED ERROR HY000: `Sys_end` must be of type `BIGINT UNSIGNED` for versioned table `t1`
create or replace table t1 ( create or replace table t1 (
A int with system versioning, A int with system versioning,
B int B int
...@@ -147,7 +147,7 @@ create or replace table t1 ( ...@@ -147,7 +147,7 @@ create or replace table t1 (
A int, A int,
B int without system versioning B int without system versioning
); );
ERROR HY000: Every field specified unversioned in versioned table ERROR HY000: Wrong parameters for versioned table `t1`: 'WITH SYSTEM VERSIONING' missing
create or replace table t1 ( create or replace table t1 (
A int, A int,
B int without system versioning B int without system versioning
...@@ -190,9 +190,9 @@ t1 CREATE TABLE `t1` ( ...@@ -190,9 +190,9 @@ t1 CREATE TABLE `t1` (
create or replace table t1 ( create or replace table t1 (
A int without system versioning A int without system versioning
); );
ERROR HY000: Every field specified unversioned in versioned table ERROR HY000: Wrong parameters for versioned table `t1`: 'WITH SYSTEM VERSIONING' missing
create or replace table t1 ( create or replace table t1 (
A int without system versioning A int without system versioning
) with system versioning; ) with system versioning;
ERROR HY000: Every field specified unversioned in versioned table ERROR HY000: Wrong parameters for versioned table `t1`: versioned fields missing
drop table t1; drop table t1;
...@@ -17,50 +17,50 @@ a b b+0 ...@@ -17,50 +17,50 @@ a b b+0
1 NULL NULL 1 NULL NULL
3 NULL NULL 3 NULL NULL
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select * from t for system_time as of timestamp now(6); select * from t for system_time as of timestamp now(6);
a b a b
1 NULL 1 NULL
3 NULL 3 NULL
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select count(*) from t group by b for system_time as of timestamp now(6); select count(*) from t group by b for system_time as of timestamp now(6);
count(*) count(*)
2 2
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select * from t for system_time as of timestamp now(6) order by b asc; select * from t for system_time as of timestamp now(6) order by b asc;
a b a b
1 NULL 1 NULL
3 NULL 3 NULL
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select * from t for system_time as of timestamp now(6) order by b desc; select * from t for system_time as of timestamp now(6) order by b desc;
a b a b
1 NULL 1 NULL
3 NULL 3 NULL
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select * from t group by a having a=2 for system_time as of timestamp now(6); select * from t group by a having a=2 for system_time as of timestamp now(6);
a b a b
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select * from t group by b having b=2 for system_time as of timestamp now(6); select * from t group by b having b=2 for system_time as of timestamp now(6);
a b a b
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select a from t where b=2 for system_time as of timestamp now(6); select a from t where b=2 for system_time as of timestamp now(6);
a a
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select a from t where b=NULL for system_time as of timestamp now(6); select a from t where b=NULL for system_time as of timestamp now(6);
a a
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select count(*), b from t group by b having b=NULL for system_time as of timestamp now(6); select count(*), b from t group by b having b=NULL for system_time as of timestamp now(6);
count(*) b count(*) b
Warnings: Warnings:
Warning 4067 Attempt to read unversioned field 'b' in historical query Warning 4055 Attempt to read unversioned field 'b' in historical query
select a, b from t; select a, b from t;
a b a b
1 2 1 2
......
...@@ -18,7 +18,7 @@ create or replace table t1 ( ...@@ -18,7 +18,7 @@ create or replace table t1 (
) with system versioning; ) with system versioning;
show create table t1; show create table t1;
--error ER_SYS_START_MORE_THAN_ONCE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -27,7 +27,7 @@ create or replace table t1 ( ...@@ -27,7 +27,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_END_COLUMN --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -35,7 +35,7 @@ create or replace table t1 ( ...@@ -35,7 +35,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_SYS_END_MORE_THAN_ONCE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -44,13 +44,13 @@ create or replace table t1 ( ...@@ -44,13 +44,13 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_SYS_START_NOT_SPECIFIED --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_SYS_END_MORE_THAN_ONCE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -59,7 +59,7 @@ create or replace table t1 ( ...@@ -59,7 +59,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
); );
--error ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_START_COLUMN --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -67,7 +67,7 @@ create or replace table t1 ( ...@@ -67,7 +67,7 @@ create or replace table t1 (
period for system_time (sys_insert, sys_remove) period for system_time (sys_insert, sys_remove)
) with system versioning; ) with system versioning;
--error ER_MISSING_WITH_SYSTEM_VERSIONING --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -75,7 +75,7 @@ create or replace table t1 ( ...@@ -75,7 +75,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
); );
--error ER_SYS_START_AND_SYS_END_SAME --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -83,7 +83,7 @@ create or replace table t1 ( ...@@ -83,7 +83,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_start) period for system_time (Sys_start, Sys_start)
); );
--error ER_SYS_START_FIELD_MUST_BE_TIMESTAMP --error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start int generated always as row start, Sys_start int generated always as row start,
...@@ -91,7 +91,7 @@ create or replace table t1 ( ...@@ -91,7 +91,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_SYS_END_FIELD_MUST_BE_TIMESTAMP --error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -99,7 +99,7 @@ create or replace table t1 ( ...@@ -99,7 +99,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning; ) with system versioning;
--error ER_SYS_START_FIELD_MUST_BE_BIGINT --error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start timestamp(6) generated always as row start, Sys_start timestamp(6) generated always as row start,
...@@ -107,7 +107,7 @@ create or replace table t1 ( ...@@ -107,7 +107,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb; ) with system versioning engine innodb;
--error ER_SYS_START_FIELD_MUST_BE_BIGINT --error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start bigint generated always as row start, Sys_start bigint generated always as row start,
...@@ -115,7 +115,7 @@ create or replace table t1 ( ...@@ -115,7 +115,7 @@ create or replace table t1 (
period for system_time (Sys_start, Sys_end) period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb; ) with system versioning engine innodb;
--error ER_SYS_END_FIELD_MUST_BE_BIGINT --error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 ( create or replace table t1 (
XNo int unsigned, XNo int unsigned,
Sys_start bigint unsigned generated always as row start, Sys_start bigint unsigned generated always as row start,
...@@ -135,7 +135,7 @@ create or replace table t1 ( ...@@ -135,7 +135,7 @@ create or replace table t1 (
) with system versioning; ) with system versioning;
show create table t1; show create table t1;
--error ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
A int, A int,
B int without system versioning B int without system versioning
...@@ -159,12 +159,12 @@ create or replace table t1 ( ...@@ -159,12 +159,12 @@ create or replace table t1 (
) with system versioning; ) with system versioning;
show create table t1; show create table t1;
--error ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
A int without system versioning A int without system versioning
); );
--error ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE --error ER_VERS_WRONG_PARAMS
create or replace table t1 ( create or replace table t1 (
A int without system versioning A int without system versioning
) with system versioning; ) with system versioning;
......
...@@ -6593,15 +6593,11 @@ static bool create_sys_trx_field(THD *thd, const char *field_name, ...@@ -6593,15 +6593,11 @@ static bool create_sys_trx_field(THD *thd, const char *field_name,
return false; return false;
} }
bool Vers_parse_info::add_versioning_info( bool Vers_parse_info::fix_implicit(
THD *thd, THD *thd,
Alter_info *alter_info, Alter_info *alter_info,
bool integer_fields) bool integer_fields)
{ {
if (!declared_system_versioning && !has_versioned_fields)
return false;
bool without_system_versioning_by_default= !declared_system_versioning;
List_iterator<Create_field> it(alter_info->create_list); List_iterator<Create_field> it(alter_info->create_list);
while (Create_field *f= it++) while (Create_field *f= it++)
{ {
...@@ -6615,11 +6611,11 @@ bool Vers_parse_info::add_versioning_info( ...@@ -6615,11 +6611,11 @@ bool Vers_parse_info::add_versioning_info(
continue; continue;
if (f->versioning == Column_definition::VERSIONING_NOT_SET && if (f->versioning == Column_definition::VERSIONING_NOT_SET &&
without_system_versioning_by_default) !declared_system_versioning ||
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG; f->versioning == Column_definition::WITHOUT_VERSIONING)
{
else if (f->versioning == Column_definition::WITHOUT_VERSIONING)
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG; f->flags|= VERS_OPTIMIZED_UPDATE_FLAG;
}
} }
// 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.
...@@ -6637,7 +6633,11 @@ bool Vers_parse_info::add_versioning_info( ...@@ -6637,7 +6633,11 @@ bool Vers_parse_info::add_versioning_info(
"sys_trx_end"); "sys_trx_end");
} }
bool Vers_parse_info::check(THD *thd, Alter_info *alter_info, bool integer_fields) bool Vers_parse_info::check_and_fix_implicit(
THD *thd,
Alter_info *alter_info,
bool integer_fields,
const char* table_name)
{ {
if (!( if (!(
has_versioned_fields || has_versioned_fields ||
...@@ -6651,10 +6651,14 @@ bool Vers_parse_info::check(THD *thd, Alter_info *alter_info, bool integer_field ...@@ -6651,10 +6651,14 @@ bool Vers_parse_info::check(THD *thd, Alter_info *alter_info, bool integer_field
return false; return false;
} }
if (add_versioning_info(thd, alter_info, integer_fields)) if (!declared_system_versioning && !has_versioned_fields)
{
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'WITH SYSTEM VERSIONING' missing");
return true; return true;
}
bool r= false; if (fix_implicit(thd, alter_info, integer_fields))
return true;
{ {
int not_set= 0; int not_set= 0;
...@@ -6685,51 +6689,42 @@ bool Vers_parse_info::check(THD *thd, Alter_info *alter_info, bool integer_field ...@@ -6685,51 +6689,42 @@ bool Vers_parse_info::check(THD *thd, Alter_info *alter_info, bool integer_field
if ((table_with_system_versioning && not_set == 0 && with == 0) || if ((table_with_system_versioning && not_set == 0 && with == 0) ||
(!table_with_system_versioning && with == 0)) (!table_with_system_versioning && with == 0))
{ {
r= true; my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "versioned fields missing");
my_error(ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE, MYF(0)); return true;
} }
} }
if (!declared_system_versioning && !has_versioned_fields)
{
r= true;
my_error(ER_MISSING_WITH_SYSTEM_VERSIONING, MYF(0));
}
if (!generated_as_row.start) if (!generated_as_row.start)
{ {
r= true; my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'GENERATED AS ROW START' column missing");
my_error(ER_SYS_START_NOT_SPECIFIED, MYF(0)); return true;
} }
if (!generated_as_row.end) if (!generated_as_row.end)
{ {
r= true; my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'GENERATED AS ROW END' column missing");
my_error(ER_SYS_END_NOT_SPECIFIED, MYF(0)); return true;
} }
if (!period_for_system_time.start || !period_for_system_time.end) if (!period_for_system_time.start || !period_for_system_time.end)
{ {
r= true; my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'PERIOD FOR SYSTEM_TIME' missing");
my_error(ER_MISSING_PERIOD_FOR_SYSTEM_TIME, MYF(0)); return true;
} }
if (!r) if (my_strcasecmp(system_charset_info, generated_as_row.start->c_ptr(),
period_for_system_time.start->c_ptr()))
{ {
if (my_strcasecmp(system_charset_info, generated_as_row.start->c_ptr(), my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW START' mismatch");
period_for_system_time.start->c_ptr())) return true;
{ }
r= true;
my_error(ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_START_COLUMN, MYF(0));
}
if (my_strcasecmp(system_charset_info, generated_as_row.end->c_ptr(), if (my_strcasecmp(system_charset_info, generated_as_row.end->c_ptr(),
period_for_system_time.end->c_ptr())) period_for_system_time.end->c_ptr()))
{ {
r= true; my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, "'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW END' mismatch");
my_error(ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_END_COLUMN, MYF(0)); return true;
}
} }
return r; // false means no error return false;
} }
...@@ -1697,8 +1697,10 @@ struct Vers_parse_info ...@@ -1697,8 +1697,10 @@ struct Vers_parse_info
period_for_system_time.end = end; period_for_system_time.end = end;
} }
bool add_versioning_info(THD *thd, Alter_info *alter_info, bool integer_fields); private:
bool check(THD *thd, Alter_info *alter_info, bool integer_fields); bool fix_implicit(THD *thd, Alter_info *alter_info, bool integer_fields);
public:
bool check_and_fix_implicit(THD *thd, Alter_info *alter_info, bool integer_fields, const char* table_name);
/** User has added 'WITH SYSTEM VERSIONING' to table definition */ /** User has added 'WITH SYSTEM VERSIONING' to table definition */
bool declared_system_versioning : 1; bool declared_system_versioning : 1;
......
...@@ -7487,56 +7487,20 @@ ER_UNKNOWN_VIEW 42S02 ...@@ -7487,56 +7487,20 @@ ER_UNKNOWN_VIEW 42S02
# MariaDB error numbers related to System Versioning # MariaDB error numbers related to System Versioning
ER_SYS_START_NOT_SPECIFIED
eng "'Generated as row start' not specified"
ER_SYS_END_NOT_SPECIFIED
eng "'Generated as row end' not specified"
ER_SYS_START_MORE_THAN_ONCE
eng "'Generated as row start' specified more than once"
ER_SYS_END_MORE_THAN_ONCE
eng "Generated as row end specified more than once"
ER_MISSING_PERIOD_FOR_SYSTEM_TIME
eng "'Period for system time' is missing"
ER_TABLE_DOESNT_SUPPORT_SYSTEM_VERSIONING ER_TABLE_DOESNT_SUPPORT_SYSTEM_VERSIONING
eng "Table '%s' doesn't support system versioning" eng "Table '%s' doesn't support system versioning"
ER_MISSING_WITH_SYSTEM_VERSIONING
eng "'With system versioning' is missing"
ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_START_COLUMN
eng "First column in 'period for system time' must be equal to 'generated as row start' column"
ER_PERIOD_FOR_SYSTEM_TIME_CONTAINS_WRONG_END_COLUMN
eng "Second column in 'period for system time' must be equal to 'generated as row end' column"
ER_SYS_START_AND_SYS_END_SAME
eng "'Period for system_time' must contain two different columns"
ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
eng "Generated field for System Versioning cannot be set by user" eng "Generated field for System Versioning cannot be set by user"
ER_UPDATE_INFO_WITH_SYSTEM_VERSIONING ER_UPDATE_INFO_WITH_SYSTEM_VERSIONING
eng "Rows matched: %ld Changed: %ld Inserted: %ld Warnings: %ld" eng "Rows matched: %ld Changed: %ld Inserted: %ld Warnings: %ld"
ER_SYS_START_FIELD_MUST_BE_TIMESTAMP ER_VERS_FIELD_WRONG_TYPE
eng "System start field must be of type TIMESTAMP" eng "%`s must be of type %`s for versioned table %`s"
ER_SYS_END_FIELD_MUST_BE_TIMESTAMP
eng "System end field must be of type TIMESTAMP"
ER_SYS_START_FIELD_MUST_BE_BIGINT
eng "System start field must be of type BIGINT UNSIGNED"
ER_SYS_END_FIELD_MUST_BE_BIGINT
eng "System end field must be of type BIGINT UNSIGNED"
ER_NO_VERSIONED_FIELDS_IN_VERSIONED_TABLE ER_VERS_WRONG_PARAMS
eng "Every field specified unversioned in versioned table" eng "Wrong parameters for versioned table %`s: %s"
ER_VERS_TRX_ID_UNSUPPORTED ER_VERS_TRX_ID_UNSUPPORTED
eng "Engine does not support versioned TRX_ID" eng "Engine does not support versioned TRX_ID"
......
...@@ -3877,8 +3877,13 @@ mysql_execute_command(THD *thd) ...@@ -3877,8 +3877,13 @@ mysql_execute_command(THD *thd)
create_info.use_default_db_type(thd); create_info.use_default_db_type(thd);
DBUG_ASSERT(create_info.db_type); DBUG_ASSERT(create_info.db_type);
if (create_info.vers_info.check(thd, &alter_info, create_info.db_type->versioned())) if (create_info.vers_info.check_and_fix_implicit(thd,
&alter_info,
create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING,
create_table->table_name))
{
goto end_with_restore_list; goto end_with_restore_list;
}
/* /*
If we are using SET CHARSET without DEFAULT, add an implicit If we are using SET CHARSET without DEFAULT, add an implicit
......
...@@ -3470,23 +3470,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3470,23 +3470,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
*/ */
if (sql_field->stored_in_db()) if (sql_field->stored_in_db())
record_offset+= sql_field->pack_length; record_offset+= sql_field->pack_length;
if (create_info->versioned())
{
const bool is_generated_as_row_start =
!my_strcasecmp(system_charset_info,
create_info->vers_info.generated_as_row.start->c_ptr(),
sql_field->field_name);
const bool is_generated_as_row_end =
!my_strcasecmp(system_charset_info,
create_info->vers_info.generated_as_row.end->c_ptr(),
sql_field->field_name);
if (is_generated_as_row_start && is_generated_as_row_end)
{
my_error(ER_SYS_START_AND_SYS_END_SAME, MYF(0), sql_field->field_name);
DBUG_RETURN(TRUE);
}
}
} }
/* Update virtual fields' offset*/ /* Update virtual fields' offset*/
it.rewind(); it.rewind();
......
...@@ -6065,7 +6065,9 @@ period_for_system_time: ...@@ -6065,7 +6065,9 @@ period_for_system_time:
Vers_parse_info &info= Lex->vers_get_info(); Vers_parse_info &info= Lex->vers_get_info();
if (!my_strcasecmp(system_charset_info, $4->c_ptr(), $6->c_ptr())) if (!my_strcasecmp(system_charset_info, $4->c_ptr(), $6->c_ptr()))
{ {
my_error(ER_SYS_START_AND_SYS_END_SAME, MYF(0), $4->c_ptr()); my_error(ER_VERS_WRONG_PARAMS, MYF(0),
Lex->create_last_non_select_table->table_name,
"'PERIOD FOR SYSTEM_TIME' columns must be different");
MYSQL_YYABORT; MYSQL_YYABORT;
} }
info.set_period_for_system_time($4, $6); info.set_period_for_system_time($4, $6);
...@@ -6174,17 +6176,19 @@ field_def: ...@@ -6174,17 +6176,19 @@ field_def:
if (!field_name) if (!field_name)
MYSQL_YYABORT; MYSQL_YYABORT;
const char *table_name= Lex->create_last_non_select_table->table_name;
String **p= NULL; String **p= NULL;
int err_nr= 0; const char* err;
switch ($4) switch ($4)
{ {
case 1: case 1:
p= &info.generated_as_row.start; p= &info.generated_as_row.start;
err_nr= ER_SYS_START_MORE_THAN_ONCE; err= "multiple 'GENERATED ALWAYS AS ROW START'";
break; break;
case 0: case 0:
p= &info.generated_as_row.end; p= &info.generated_as_row.end;
err_nr= ER_SYS_END_MORE_THAN_ONCE; err= "multiple 'GENERATED ALWAYS AS ROW END'";
break; break;
default: default:
/* Not Reachable */ /* Not Reachable */
...@@ -6193,7 +6197,7 @@ field_def: ...@@ -6193,7 +6197,7 @@ field_def:
} }
if (*p) if (*p)
{ {
my_error(err_nr, MYF(0), field_name->c_ptr()); my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name, err);
MYSQL_YYABORT; MYSQL_YYABORT;
} }
*p= field_name; *p= field_name;
......
...@@ -2566,13 +2566,13 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, ...@@ -2566,13 +2566,13 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (vers_start_field()->type() != MYSQL_TYPE_LONGLONG if (vers_start_field()->type() != MYSQL_TYPE_LONGLONG
|| !(vers_start_field()->flags & UNSIGNED_FLAG)) || !(vers_start_field()->flags & UNSIGNED_FLAG))
{ {
my_error(ER_SYS_START_FIELD_MUST_BE_BIGINT, MYF(0), share->table_name); my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0), vers_start_field()->field_name, "BIGINT UNSIGNED", share->table_name);
goto err; goto err;
} }
if (vers_end_field()->type() != MYSQL_TYPE_LONGLONG if (vers_end_field()->type() != MYSQL_TYPE_LONGLONG
|| !(vers_end_field()->flags & UNSIGNED_FLAG)) || !(vers_end_field()->flags & UNSIGNED_FLAG))
{ {
my_error(ER_SYS_END_FIELD_MUST_BE_BIGINT, MYF(0), share->table_name); my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0), vers_end_field()->field_name, "BIGINT UNSIGNED", share->table_name);
goto err; goto err;
} }
} }
...@@ -2580,12 +2580,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, ...@@ -2580,12 +2580,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
{ {
if (vers_start_field()->type() != MYSQL_TYPE_TIMESTAMP) if (vers_start_field()->type() != MYSQL_TYPE_TIMESTAMP)
{ {
my_error(ER_SYS_START_FIELD_MUST_BE_TIMESTAMP, MYF(0), share->table_name); my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0), vers_start_field()->field_name, "TIMESTAMP", share->table_name);
goto err; goto err;
} }
if (vers_end_field()->type() != MYSQL_TYPE_TIMESTAMP) if (vers_end_field()->type() != MYSQL_TYPE_TIMESTAMP)
{ {
my_error(ER_SYS_END_FIELD_MUST_BE_TIMESTAMP, MYF(0), share->table_name); my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0), vers_end_field()->field_name, "TIMESTAMP", share->table_name);
goto err; goto err;
} }
} // if (db_type()->versioned()) } // if (db_type()->versioned())
......
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