mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-30016 Virtual columns do not support autoincrement columns
change vcol_upgrade test to use stored gcols
This commit is contained in:
parent
a6b327e90a
commit
ae53f684d3
8 changed files with 55 additions and 7 deletions
Binary file not shown.
Binary file not shown.
|
@ -49,18 +49,18 @@ alter table t1 add column (h int generated always as (a+1) virtual, i int as(5)
|
|||
drop table t1;
|
||||
|
||||
--echo # DEFAULT
|
||||
--error 1064
|
||||
--error ER_PARSE_ERROR
|
||||
create table t1 (a int, b int generated always as (a+1) virtual default 0);
|
||||
create table t1 (a int);
|
||||
--error 1064
|
||||
--error ER_PARSE_ERROR
|
||||
alter table t1 add column b int generated always as (a+1) virtual default 0;
|
||||
drop table t1;
|
||||
|
||||
--echo # AUTO_INCREMENT
|
||||
--error 1064
|
||||
--error ER_PARSE_ERROR
|
||||
create table t1 (a int, b int generated always as (a+1) virtual AUTO_INCREMENT);
|
||||
create table t1 (a int);
|
||||
--error 1064
|
||||
--error ER_PARSE_ERROR
|
||||
alter table t1 add column b int generated always as (a+1) virtual AUTO_INCREMENT;
|
||||
drop table t1;
|
||||
|
||||
|
@ -138,7 +138,7 @@ create table t1 (a int, b int generated always as (a % 2) stored references t2(a
|
|||
show create table t1;
|
||||
drop table t1;
|
||||
create table t1 (a int, b int generated always as (a % 2) virtual);
|
||||
--error 1064
|
||||
--error ER_PARSE_ERROR
|
||||
alter table t1 modify b int generated always as (a % 2) stored references t2(a);
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
|
@ -199,6 +199,13 @@ create table t1 (a int, b int generated always as(-b) virtual, c int generated a
|
|||
create table t1 (a int, b int generated always as(-c) virtual, c int generated always as (b + 1) virtual);
|
||||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
|
||||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
|
||||
show create table t1;
|
||||
insert t1 (col_int_key) values (10),(20),(30);
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
--echo # Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
|
||||
create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
|
||||
|
|
|
@ -260,6 +260,24 @@ create table t1 (a int, b int generated always as(-c) virtual, c int generated a
|
|||
ERROR 01000: Expression for field `b` is referring to uninitialized field `c`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
|
||||
ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
|
||||
ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) GENERATED ALWAYS AS (`pk` + `col_int_key`) VIRTUAL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||
insert t1 (col_int_key) values (10),(20),(30);
|
||||
select * from t1;
|
||||
pk col_int_nokey col_int_key
|
||||
1 11 10
|
||||
2 22 20
|
||||
3 33 30
|
||||
drop table t1;
|
||||
# Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
|
||||
create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
|
||||
insert into t1(a) values(1),(2);
|
||||
|
|
|
@ -260,6 +260,24 @@ create table t1 (a int, b int generated always as(-c) virtual, c int generated a
|
|||
ERROR 01000: Expression for field `b` is referring to uninitialized field `c`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
|
||||
ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
|
||||
ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
|
||||
create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) GENERATED ALWAYS AS (`pk` + `col_int_key`) VIRTUAL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||
insert t1 (col_int_key) values (10),(20),(30);
|
||||
select * from t1;
|
||||
pk col_int_nokey col_int_key
|
||||
1 11 10
|
||||
2 22 20
|
||||
3 33 30
|
||||
drop table t1;
|
||||
# Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
|
||||
create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
|
||||
insert into t1(a) values(1),(2);
|
||||
|
|
|
@ -6,7 +6,7 @@ show create table vcol_autoinc;
|
|||
Table Create Table
|
||||
vcol_autoinc CREATE TABLE `vcol_autoinc` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`v3` int(11) GENERATED ALWAYS AS (`pk`) VIRTUAL,
|
||||
`v3` int(11) GENERATED ALWAYS AS (`pk`) STORED,
|
||||
PRIMARY KEY (`pk`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||
select * from vcol_autoinc;
|
||||
|
|
|
@ -498,6 +498,8 @@ enum enum_vcol_info_type
|
|||
VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED,
|
||||
VCOL_DEFAULT, VCOL_CHECK_FIELD, VCOL_CHECK_TABLE,
|
||||
/* Additional types should be added here */
|
||||
|
||||
VCOL_GENERATED_VIRTUAL_INDEXED, // this is never written in .frm
|
||||
/* Following is the highest value last */
|
||||
VCOL_TYPE_NONE = 127 // Since the 0 value is already in use
|
||||
};
|
||||
|
@ -507,6 +509,7 @@ static inline const char *vcol_type_name(enum_vcol_info_type type)
|
|||
switch (type)
|
||||
{
|
||||
case VCOL_GENERATED_VIRTUAL:
|
||||
case VCOL_GENERATED_VIRTUAL_INDEXED:
|
||||
case VCOL_GENERATED_STORED:
|
||||
return "GENERATED ALWAYS AS";
|
||||
case VCOL_DEFAULT:
|
||||
|
|
|
@ -2629,6 +2629,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
|
|||
share->stored_fields--;
|
||||
if (reg_field->flags & BLOB_FLAG)
|
||||
share->virtual_not_stored_blob_fields++;
|
||||
if (reg_field->flags & PART_KEY_FLAG)
|
||||
vcol_info->set_vcol_type(VCOL_GENERATED_VIRTUAL_INDEXED);
|
||||
/* Correct stored_rec_length as non stored fields are last */
|
||||
recpos= (uint) (reg_field->ptr - record);
|
||||
if (share->stored_rec_length >= recpos)
|
||||
|
@ -3159,7 +3161,7 @@ bool Virtual_column_info::fix_and_check_expr(THD *thd, TABLE *table)
|
|||
get_vcol_type_name(), name.str);
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
else if (unlikely(res.errors & VCOL_AUTO_INC))
|
||||
else if (res.errors & VCOL_AUTO_INC && vcol_type != VCOL_GENERATED_VIRTUAL)
|
||||
{
|
||||
/*
|
||||
An auto_increment field may not be used in an expression for
|
||||
|
|
Loading…
Reference in a new issue