Commit 7e04f7c8 authored by Michael Widenius's avatar Michael Widenius

Fixed that SHOW COLUMNS for a virtual persistent column shows 'PERSISTENT' instead of 'VIRTUAL'

Strict mode now gives error if one tries to update a virtual column.

mysql-test/suite/vcol/r/vcol_column_def_options_innodb.result:
  Updated test results
mysql-test/suite/vcol/r/vcol_column_def_options_myisam.result:
  Updated test results
mysql-test/suite/vcol/r/vcol_keys_innodb.result:
  Updated test results
mysql-test/suite/vcol/r/vcol_keys_myisam.result:
  Updated test results
mysql-test/suite/vcol/r/vcol_misc.result:
  Added new test for 'show columns' and error handling when trying to update a virtual column.
mysql-test/suite/vcol/t/vcol_misc.test:
  Added new test for 'show columns' and error handling when trying to update a virtual column.
sql/sql_base.cc:
  Strict mode now gives error if one tries to update a virtual column.
sql/sql_show.cc:
  Show PERSISTENT instead of VIRTUAL for persistent columns.
parent f0f2ec30
......@@ -114,7 +114,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES NULL VIRTUAL
b int(11) YES NULL PERSISTENT
insert into t1 (a) values (1);
select * from t1;
a b
......
......@@ -114,7 +114,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES NULL VIRTUAL
b int(11) YES NULL PERSISTENT
insert into t1 (a) values (1);
select * from t1;
a b
......
......@@ -19,7 +19,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES UNI NULL VIRTUAL
b int(11) YES UNI NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2), unique key (b));
ERROR HY000: Key/Index cannot be defined on a non-stored computed column
......@@ -34,7 +34,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES UNI NULL VIRTUAL
b int(11) YES UNI NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2));
alter table t1 add unique key (b);
......@@ -64,7 +64,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES MUL NULL VIRTUAL
b int(11) YES MUL NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2) persistent, index (a,b));
show create table t1;
......@@ -77,7 +77,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES MUL NULL
b int(11) YES NULL VIRTUAL
b int(11) YES NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2));
alter table t1 add index (b);
......
......@@ -19,7 +19,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES UNI NULL VIRTUAL
b int(11) YES UNI NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2), unique key (b));
ERROR HY000: Key/Index cannot be defined on a non-stored computed column
......@@ -34,7 +34,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES UNI NULL VIRTUAL
b int(11) YES UNI NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2));
alter table t1 add unique key (b);
......@@ -64,7 +64,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(11) YES MUL NULL VIRTUAL
b int(11) YES MUL NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2) persistent, index (a,b));
show create table t1;
......@@ -77,7 +77,7 @@ t1 CREATE TABLE `t1` (
describe t1;
Field Type Null Key Default Extra
a int(11) YES MUL NULL
b int(11) YES NULL VIRTUAL
b int(11) YES NULL PERSISTENT
drop table t1;
create table t1 (a int, b int as (a*2));
alter table t1 add index (b);
......
......@@ -203,3 +203,42 @@ a b
1 1
3 0
drop table t1;
CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) AS (a MOD 10) VIRTUAL,
`d` varchar(5) AS (LEFT(b,5)) PERSISTENT
) ENGINE=MyISAM;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) AS (a MOD 10) VIRTUAL,
`d` varchar(5) AS (LEFT(b,5)) PERSISTENT
) ENGINE=MyISAM DEFAULT CHARSET=latin1
show columns from t1;
Field Type Null Key Default Extra
a int(11) NO NULL
b varchar(32) YES NULL
c int(11) YES NULL VIRTUAL
d varchar(5) YES NULL PERSISTENT
show full columns from t1;
Field Type Collation Null Key Default Extra Privileges Comment
a int(11) NULL NO NULL select,insert,update,references
b varchar(32) latin1_swedish_ci YES NULL select,insert,update,references
c int(11) NULL YES NULL VIRTUAL select,insert,update,references
d varchar(5) latin1_swedish_ci YES NULL PERSISTENT select,insert,update,references
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,NULL);
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
Warnings:
Warning 1906 The value specified for computed column 'd' in table 't1' ignored
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
Warnings:
Warning 1906 The value specified for computed column 'd' in table 't1' ignored
set sql_mode='strict_all_tables';
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
ERROR HY000: The value specified for computed column 'd' in table 't1' ignored
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
ERROR HY000: The value specified for computed column 'd' in table 't1' ignored
drop table t1;
......@@ -182,3 +182,26 @@ insert into t1 (a) values (1),(3);
select * from t1;
select * from t1;
drop table t1;
#
# Test output of show columns
#
CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) AS (a MOD 10) VIRTUAL,
`d` varchar(5) AS (LEFT(b,5)) PERSISTENT
) ENGINE=MyISAM;
show create table t1;
show columns from t1;
show full columns from t1;
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,NULL);
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
set sql_mode='strict_all_tables';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
drop table t1;
......@@ -8394,12 +8394,10 @@ fill_record(THD * thd, List<Item> &fields, List<Item> &values,
value->type() != Item::NULL_ITEM &&
table->s->table_category != TABLE_CATEGORY_TEMPORARY)
{
thd->abort_on_warning= FALSE;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
rfield->field_name, table->s->table_name.str);
thd->abort_on_warning= abort_on_warning_saved;
}
if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
{
......@@ -8549,12 +8547,10 @@ fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors,
value->type() != Item::NULL_ITEM &&
table->s->table_category != TABLE_CATEGORY_TEMPORARY)
{
thd->abort_on_warning= FALSE;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
field->field_name, table->s->table_name.str);
thd->abort_on_warning= abort_on_warning_saved;
}
if (use_value)
......
......@@ -4474,8 +4474,12 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
table->field[17]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
cs);
if (field->vcol_info)
table->field[17]->store(STRING_WITH_LEN("VIRTUAL"), cs);
{
if (field->stored_in_db)
table->field[17]->store(STRING_WITH_LEN("PERSISTENT"), cs);
else
table->field[17]->store(STRING_WITH_LEN("VIRTUAL"), cs);
}
table->field[19]->store(field->comment.str, field->comment.length, cs);
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
......
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