Commit 16be7469 authored by Sachin Setiya's avatar Sachin Setiya Committed by Sachin Setiya

MDEV-14849 CREATE + ALTER with user-invisible columns produce ...

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.
parent 2d73b581
......@@ -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);
......@@ -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;
......
......@@ -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);
......
......@@ -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 */
......@@ -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 */
......
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