Skip to content

Commit 33ec445

Browse files
committed
MDEV-10370 Check constraints on virtual columns fails on INSERT when column not specified
add columns needed for CHECK constraints not only to read_set, but also to vcol_set.
1 parent 1216244 commit 33ec445

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

mysql-test/r/check_constraint.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ t1 CREATE TABLE `t1` (
131131
CONSTRAINT `CONSTRAINT_2` CHECK (`a` > `b`)
132132
) ENGINE=MyISAM DEFAULT CHARSET=latin1
133133
drop table t1;
134+
create table t1(c1 int, c2 int as (c1 + 1), check (c2 > 2));
135+
insert into t1(c1) values(1);
136+
ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1`
137+
insert into t1(c1) values(2);
138+
drop table t1;

mysql-test/t/check_constraint.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ create or replace table t1 (a int, b int,
6969
constraint CONSTRAINT_2 check (a>b));
7070
show create table t1;
7171
drop table t1;
72+
73+
#
74+
# MDEV-10370 Check constraints on virtual columns fails on INSERT when column not specified
75+
#
76+
create table t1(c1 int, c2 int as (c1 + 1), check (c2 > 2));
77+
--error ER_CONSTRAINT_FAILED
78+
insert into t1(c1) values(1);
79+
insert into t1(c1) values(2);
80+
drop table t1;

sql/table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6605,6 +6605,8 @@ void TABLE::mark_columns_used_by_check_constraints(void)
66056605
void TABLE::mark_check_constraint_columns_for_read(void)
66066606
{
66076607
bitmap_union(read_set, s->check_set);
6608+
if (vcol_set)
6609+
bitmap_union(vcol_set, s->check_set);
66086610
}
66096611

66106612

0 commit comments

Comments
 (0)