Skip to content

Commit

Permalink
MDEV-10370 Check constraints on virtual columns fails on INSERT when …
Browse files Browse the repository at this point in the history
…column not specified

add columns needed for CHECK constraints not only to read_set,
but also to vcol_set.
  • Loading branch information
vuvova committed Mar 28, 2017
1 parent 1216244 commit 33ec445
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mysql-test/r/check_constraint.result
Expand Up @@ -131,3 +131,8 @@ t1 CREATE TABLE `t1` (
CONSTRAINT `CONSTRAINT_2` CHECK (`a` > `b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(c1 int, c2 int as (c1 + 1), check (c2 > 2));
insert into t1(c1) values(1);
ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1`
insert into t1(c1) values(2);
drop table t1;
9 changes: 9 additions & 0 deletions mysql-test/t/check_constraint.test
Expand Up @@ -69,3 +69,12 @@ create or replace table t1 (a int, b int,
constraint CONSTRAINT_2 check (a>b));
show create table t1;
drop table t1;

#
# MDEV-10370 Check constraints on virtual columns fails on INSERT when column not specified
#
create table t1(c1 int, c2 int as (c1 + 1), check (c2 > 2));
--error ER_CONSTRAINT_FAILED
insert into t1(c1) values(1);
insert into t1(c1) values(2);
drop table t1;
2 changes: 2 additions & 0 deletions sql/table.cc
Expand Up @@ -6605,6 +6605,8 @@ void TABLE::mark_columns_used_by_check_constraints(void)
void TABLE::mark_check_constraint_columns_for_read(void)
{
bitmap_union(read_set, s->check_set);
if (vcol_set)
bitmap_union(vcol_set, s->check_set);
}


Expand Down

0 comments on commit 33ec445

Please sign in to comment.