Skip to content

Commit 1f78400

Browse files
committed
MDEV-29833 CREATE ... SELECT system_versioned_table causes invalid defaults
ROW START/END fields shold have no default value
1 parent 768a10d commit 1f78400

File tree

6 files changed

+25
-30
lines changed

6 files changed

+25
-30
lines changed

mysql-test/suite/versioning/r/create.result

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
drop table if exists t1;
21
create table t1 (
32
x1 int unsigned,
43
Sys_start SYS_DATATYPE as row start invisible comment 'start',
@@ -266,8 +265,8 @@ show create table t3;
266265
Table Create Table
267266
t3 CREATE TABLE `t3` (
268267
`y` int(11) DEFAULT NULL,
269-
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
270-
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
268+
`st` timestamp(6) NOT NULL,
269+
`en` timestamp(6) NOT NULL
271270
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
272271
## For versioned table
273272
insert into t1 values (1);
@@ -296,8 +295,8 @@ show create table t3;
296295
Table Create Table
297296
t3 CREATE TABLE `t3` (
298297
`y` int(11) DEFAULT NULL,
299-
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
300-
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
298+
`st` timestamp(6) NOT NULL,
299+
`en` timestamp(6) NOT NULL
301300
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
302301
select * from t3 where y > 2;
303302
y st en
@@ -385,17 +384,17 @@ show create table t2;
385384
Table Create Table
386385
t2 CREATE TABLE `t2` (
387386
`x25` int(11) DEFAULT NULL,
388-
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
389-
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
387+
`row_start` timestamp(6) NOT NULL,
388+
`row_end` timestamp(6) NOT NULL
390389
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
391390
create or replace table t2 with system versioning
392391
as select x25, row_start rs, row_end re from t1;
393392
show create table t2;
394393
Table Create Table
395394
t2 CREATE TABLE `t2` (
396395
`x25` int(11) DEFAULT NULL,
397-
`rs` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
398-
`re` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
396+
`rs` timestamp(6) NOT NULL,
397+
`re` timestamp(6) NOT NULL
399398
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
400399
create or replace table t1 (
401400
x26 int,
@@ -409,8 +408,8 @@ show create table t2;
409408
Table Create Table
410409
t2 CREATE TABLE `t2` (
411410
`x26` int(11) DEFAULT NULL,
412-
`st` bigint(20) unsigned NOT NULL DEFAULT 0,
413-
`en` bigint(20) unsigned NOT NULL DEFAULT 0
411+
`st` bigint(20) unsigned NOT NULL,
412+
`en` bigint(20) unsigned NOT NULL
414413
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
415414
create or replace table t1 (x27 int, id int) with system versioning engine NON_DEFAULT_ENGINE;
416415
create or replace table t2 (b int, id int);
@@ -421,8 +420,8 @@ Table Create Table
421420
t3 CREATE TABLE `t3` (
422421
`b` int(11) DEFAULT NULL,
423422
`x27` int(11) DEFAULT NULL,
424-
`rs` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
425-
`re` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
423+
`rs` timestamp(6) NOT NULL,
424+
`re` timestamp(6) NOT NULL
426425
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
427426
## Errors
428427
create or replace temporary table t (x28 int) with system versioning;
@@ -458,10 +457,10 @@ Table Create Table
458457
t3 CREATE TABLE `t3` (
459458
`x30` int(11) DEFAULT NULL,
460459
`y` int(11) DEFAULT NULL,
461-
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
462-
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
463-
`st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
464-
`en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
460+
`row_start` timestamp(6) NOT NULL,
461+
`row_end` timestamp(6) NOT NULL,
462+
`st` timestamp(6) NOT NULL,
463+
`en` timestamp(6) NOT NULL
465464
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
466465
create or replace table t3 (
467466
y int,
@@ -475,8 +474,8 @@ Table Create Table
475474
t3 CREATE TABLE `t3` (
476475
`x30` int(11) DEFAULT NULL,
477476
`y` int(11) DEFAULT NULL,
478-
`row_start` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
479-
`row_end` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
477+
`row_start` timestamp(6) NOT NULL,
478+
`row_end` timestamp(6) NOT NULL,
480479
`st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
481480
`en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
482481
PERIOD FOR SYSTEM_TIME (`st`, `en`)

mysql-test/suite/versioning/t/create.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
--source suite/versioning/engines.inc
22
--source suite/versioning/common.inc
33

4-
--disable_warnings
5-
drop table if exists t1;
6-
--enable_warnings
7-
84
--enable_prepare_warnings
95

106
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype_expl SYS_DATATYPE NULL ''

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8084,7 +8084,7 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int f
80848084
f->field_name.str= field_name;
80858085
f->field_name.length= strlen(field_name);
80868086
f->charset= system_charset_info;
8087-
f->flags= flags | NOT_NULL_FLAG;
8087+
f->flags= flags | NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG;
80888088
if (integer)
80898089
{
80908090
DBUG_ASSERT(0); // Not implemented yet

sql/sql_insert.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
320320

321321
static bool has_no_default_value(THD *thd, Field *field, TABLE_LIST *table_list)
322322
{
323-
if ((field->flags & NO_DEFAULT_VALUE_FLAG) && field->real_type() != MYSQL_TYPE_ENUM)
323+
if ((field->flags & (NO_DEFAULT_VALUE_FLAG | VERS_ROW_START | VERS_ROW_END))
324+
== NO_DEFAULT_VALUE_FLAG && field->real_type() != MYSQL_TYPE_ENUM)
324325
{
325326
bool view= false;
326327
if (table_list)
@@ -2257,9 +2258,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, TABLE_LIST *t
22572258
for (Field **field=entry->field ; *field ; field++)
22582259
{
22592260
if (!bitmap_is_set(write_set, (*field)->field_index) &&
2260-
!(*field)->vers_sys_field() &&
2261-
has_no_default_value(thd, *field, table_list) &&
2262-
((*field)->real_type() != MYSQL_TYPE_ENUM))
2261+
has_no_default_value(thd, *field, table_list))
22632262
err=1;
22642263
}
22652264
return thd->abort_on_warning ? err : 0;

sql/sql_lex.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9810,7 +9810,7 @@ bool LEX::last_field_generated_always_as_row_start_or_end(Lex_ident *p,
98109810
last_field->field_name.str);
98119811
return true;
98129812
}
9813-
last_field->flags|= (flag | NOT_NULL_FLAG);
9813+
last_field->flags|= (flag | NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG);
98149814
DBUG_ASSERT(p);
98159815
*p= last_field->field_name;
98169816
return false;

sql/sql_table.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3793,7 +3793,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
37933793
}
37943794
if (sql_field->invisible == INVISIBLE_USER &&
37953795
sql_field->flags & NOT_NULL_FLAG &&
3796-
sql_field->flags & NO_DEFAULT_VALUE_FLAG)
3796+
sql_field->flags & NO_DEFAULT_VALUE_FLAG &&
3797+
!sql_field->vers_sys_field())
37973798
{
37983799
my_error(ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT, MYF(0),
37993800
sql_field->field_name.str);

0 commit comments

Comments
 (0)