diff --git a/mysql-test/r/check_constraint.result b/mysql-test/r/check_constraint.result index 59fbb8adf57..1743bb97047 100644 --- a/mysql-test/r/check_constraint.result +++ b/mysql-test/r/check_constraint.result @@ -136,3 +136,7 @@ insert into t1(c1) values(1); ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1` insert into t1(c1) values(2); drop table t1; +create table t1 (a int, b int, check(a>0)); +alter table t1 drop column a; +ERROR 42S22: Unknown column 'a' in 'CHECK' +drop table t1; diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result index 39202f5eabb..19150a15807 100644 --- a/mysql-test/r/default.result +++ b/mysql-test/r/default.result @@ -541,10 +541,10 @@ DROP FUNCTION f1; CREATE PROCEDURE p1(par INT) CREATE TABLE t1 (a INT DEFAULT par); ERROR HY000: Function or expression 'par' cannot be used in the DEFAULT clause of `a` CREATE TABLE t1 (a INT DEFAULT par); -ERROR 42S22: Unknown column 'par' in 'virtual column function' +ERROR 42S22: Unknown column 'par' in 'DEFAULT' CREATE PROCEDURE p1() CREATE TABLE t1 (a INT DEFAULT par); CALL p1; -ERROR 42S22: Unknown column 'par' in 'virtual column function' +ERROR 42S22: Unknown column 'par' in 'DEFAULT' DROP PROCEDURE p1; CREATE TABLE t1 (a INT DEFAULT VALUES(a)); ERROR HY000: Function or expression 'values()' cannot be used in the DEFAULT clause of `a` diff --git a/mysql-test/t/check_constraint.test b/mysql-test/t/check_constraint.test index 643ead2439b..7c5d30b6cd3 100644 --- a/mysql-test/t/check_constraint.test +++ b/mysql-test/t/check_constraint.test @@ -78,3 +78,11 @@ create table t1(c1 int, c2 int as (c1 + 1), check (c2 > 2)); insert into t1(c1) values(1); insert into t1(c1) values(2); drop table t1; + +# +# MDEV-11114 Cannot drop column referenced by CHECK constraint: Unknown column 'a' in 'virtual column function' +# +create table t1 (a int, b int, check(a>0)); +--error ER_BAD_FIELD_ERROR +alter table t1 drop column a; +drop table t1; diff --git a/sql/table.cc b/sql/table.cc index 03117f8ec63..3a08d1e49ea 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1060,6 +1060,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, expr_str.length(parse_vcol_keyword.length); expr_str.append((char*)pos, expr_length); + thd->where= vcol_type_name(static_cast(type)); switch (type) { case VCOL_GENERATED_VIRTUAL: @@ -2691,13 +2692,9 @@ static bool fix_vcol_expr(THD *thd, Virtual_column_info *vcol) const enum enum_mark_columns save_mark_used_columns= thd->mark_used_columns; thd->mark_used_columns= MARK_COLUMNS_NONE; - const char *save_where= thd->where; - thd->where= "virtual column function"; - int error= vcol->expr->fix_fields(thd, &vcol->expr); thd->mark_used_columns= save_mark_used_columns; - thd->where= save_where; if (unlikely(error)) {