Skip to content

Commit

Permalink
MDEV-14849 CREATE + ALTER with user-invisible columns produce ...
Browse files Browse the repository at this point in the history
Problem:-
  create or replace table t1 (pk int auto_increment primary key invisible, i int);
  alter table t1 modify pk int invisible;
 This last alter makes a invisible column which is not null and does not
 have default value.

Analysis:-
 This is caused because our error check for NOT_NULL_FLAG and
 NO_DEFAULT_VALUE_FLAG flag misses this sql_field , but this is not the fault
 of error check :).Actually this field come via mysql_prepare_alter_table
 and it does not have NO_DEFAULT_VALUE_FLAG flag turned on. (If it was create
 table NO_DEFAULT_VALUE_FLAG would have turned on Column_definition::check)
 and this would have generated error.

Solution:-
 I have moved the error check to kind last of mysql_prepare_create_table
 because upto this point we have applied NO_DEFAULT_VALUE_FLAG to required
 column.
  • Loading branch information
Sachin Setiya authored and mariadb-SachinSetiya committed Feb 2, 2018
1 parent 2d73b58 commit 16be746
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 7 additions & 2 deletions mysql-test/r/invisible_field.result
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
create table t1(a1 int primary key invisible ,a2 int unique invisible , a3 blob,a4 int not null invisible unique);
ERROR HY000: Invisible column `a1` must have a default value
create table t1(abc int not null invisible);
ERROR HY000: Invisible column `abc` must have a default value
ERROR 42000: A table must have at least 1 column
MDEV-14849 CREATE + ALTER with user-invisible columns produce invalid table definition
create or replace table t1 (pk int auto_increment primary key invisible, i int);
alter table t1 modify pk int invisible;
ERROR HY000: Invisible column `pk` must have a default value
drop table t1;
create table t1(a int invisible, b int);
insert into t1 values(1);
insert into t1(a) values(2);
Expand Down Expand Up @@ -439,7 +444,7 @@ d int(11) YES UNI NULL
drop table t1;
SHOW STATUS LIKE 'Feature_invisible_columns';
Variable_name Value
Feature_invisible_columns 50
Feature_invisible_columns 52
#invisible is non reserved
create table t1(a int unique , invisible int invisible, c int );
desc t1;
Expand Down
7 changes: 6 additions & 1 deletion mysql-test/t/invisible_field.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ create table t1(a1 int invisible);
create table t1(a1 blob,invisible(a1));
--error ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT
create table t1(a1 int primary key invisible ,a2 int unique invisible , a3 blob,a4 int not null invisible unique);
--error ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT
--error ER_TABLE_MUST_HAVE_COLUMNS
create table t1(abc int not null invisible);
--echo MDEV-14849 CREATE + ALTER with user-invisible columns produce invalid table definition
create or replace table t1 (pk int auto_increment primary key invisible, i int);
--error ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT
alter table t1 modify pk int invisible;
drop table t1;
create table t1(a int invisible, b int);
#should automatically add null
insert into t1 values(1);
Expand Down
16 changes: 8 additions & 8 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3593,14 +3593,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
record_offset+= sql_field->pack_length;
if (sql_field->flags & VERS_SYSTEM_FIELD)
continue;
if (sql_field->invisible == INVISIBLE_USER &&
sql_field->flags & NOT_NULL_FLAG &&
sql_field->flags & NO_DEFAULT_VALUE_FLAG)
{
my_error(ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT, MYF(0),
sql_field->field_name.str);
DBUG_RETURN(TRUE);
}
}
/* Update virtual fields' offset and give error if
All fields are invisible */
Expand Down Expand Up @@ -4244,6 +4236,14 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name.str);
DBUG_RETURN(TRUE);
}
if (sql_field->invisible == INVISIBLE_USER &&
sql_field->flags & NOT_NULL_FLAG &&
sql_field->flags & NO_DEFAULT_VALUE_FLAG)
{
my_error(ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT, MYF(0),
sql_field->field_name.str);
DBUG_RETURN(TRUE);
}
}

/* Check table level constraints */
Expand Down

0 comments on commit 16be746

Please sign in to comment.