Commit 1f784008 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-29833 CREATE ... SELECT system_versioned_table causes invalid defaults

ROW START/END fields shold have no default value
parent 768a10d0
drop table if exists t1;
create table t1 (
x1 int unsigned,
Sys_start SYS_DATATYPE as row start invisible comment 'start',
......@@ -266,8 +265,8 @@ show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`y` int(11) DEFAULT NULL,
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`st` timestamp(6) NOT NULL,
`en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
## For versioned table
insert into t1 values (1);
......@@ -296,8 +295,8 @@ show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`y` int(11) DEFAULT NULL,
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`st` timestamp(6) NOT NULL,
`en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select * from t3 where y > 2;
y st en
......@@ -385,8 +384,8 @@ show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x25` int(11) DEFAULT NULL,
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`row_start` timestamp(6) NOT NULL,
`row_end` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create or replace table t2 with system versioning
as select x25, row_start rs, row_end re from t1;
......@@ -394,8 +393,8 @@ show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x25` int(11) DEFAULT NULL,
`rs` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`re` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`rs` timestamp(6) NOT NULL,
`re` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x26 int,
......@@ -409,8 +408,8 @@ show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x26` int(11) DEFAULT NULL,
`st` bigint(20) unsigned NOT NULL DEFAULT 0,
`en` bigint(20) unsigned NOT NULL DEFAULT 0
`st` bigint(20) unsigned NOT NULL,
`en` bigint(20) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (x27 int, id int) with system versioning engine NON_DEFAULT_ENGINE;
create or replace table t2 (b int, id int);
......@@ -421,8 +420,8 @@ Table Create Table
t3 CREATE TABLE `t3` (
`b` int(11) DEFAULT NULL,
`x27` int(11) DEFAULT NULL,
`rs` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`re` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`rs` timestamp(6) NOT NULL,
`re` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
## Errors
create or replace temporary table t (x28 int) with system versioning;
......@@ -458,10 +457,10 @@ Table Create Table
t3 CREATE TABLE `t3` (
`x30` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
`row_start` timestamp(6) NOT NULL,
`row_end` timestamp(6) NOT NULL,
`st` timestamp(6) NOT NULL,
`en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create or replace table t3 (
y int,
......@@ -475,8 +474,8 @@ Table Create Table
t3 CREATE TABLE `t3` (
`x30` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`row_start` timestamp(6) NOT NULL,
`row_end` timestamp(6) NOT NULL,
`st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
`en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME (`st`, `en`)
......
--source suite/versioning/engines.inc
--source suite/versioning/common.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
--enable_prepare_warnings
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype_expl SYS_DATATYPE NULL ''
......
......@@ -8084,7 +8084,7 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int f
f->field_name.str= field_name;
f->field_name.length= strlen(field_name);
f->charset= system_charset_info;
f->flags= flags | NOT_NULL_FLAG;
f->flags= flags | NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG;
if (integer)
{
DBUG_ASSERT(0); // Not implemented yet
......
......@@ -320,7 +320,8 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
static bool has_no_default_value(THD *thd, Field *field, TABLE_LIST *table_list)
{
if ((field->flags & NO_DEFAULT_VALUE_FLAG) && field->real_type() != MYSQL_TYPE_ENUM)
if ((field->flags & (NO_DEFAULT_VALUE_FLAG | VERS_ROW_START | VERS_ROW_END))
== NO_DEFAULT_VALUE_FLAG && field->real_type() != MYSQL_TYPE_ENUM)
{
bool view= false;
if (table_list)
......@@ -2257,9 +2258,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, TABLE_LIST *t
for (Field **field=entry->field ; *field ; field++)
{
if (!bitmap_is_set(write_set, (*field)->field_index) &&
!(*field)->vers_sys_field() &&
has_no_default_value(thd, *field, table_list) &&
((*field)->real_type() != MYSQL_TYPE_ENUM))
has_no_default_value(thd, *field, table_list))
err=1;
}
return thd->abort_on_warning ? err : 0;
......
......@@ -9810,7 +9810,7 @@ bool LEX::last_field_generated_always_as_row_start_or_end(Lex_ident *p,
last_field->field_name.str);
return true;
}
last_field->flags|= (flag | NOT_NULL_FLAG);
last_field->flags|= (flag | NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG);
DBUG_ASSERT(p);
*p= last_field->field_name;
return false;
......
......@@ -3793,7 +3793,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
if (sql_field->invisible == INVISIBLE_USER &&
sql_field->flags & NOT_NULL_FLAG &&
sql_field->flags & NO_DEFAULT_VALUE_FLAG)
sql_field->flags & NO_DEFAULT_VALUE_FLAG &&
!sql_field->vers_sys_field())
{
my_error(ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT, MYF(0),
sql_field->field_name.str);
......
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