Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDEV-11114 Cannot drop column referenced by CHECK constraint: Unknown…
… column 'a' in 'virtual column function'

clarify the error message
  • Loading branch information
vuvova committed Mar 28, 2017
1 parent 33ec445 commit 7a1b058
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mysql-test/r/check_constraint.result
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions mysql-test/r/default.result
Expand Up @@ -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`
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/t/check_constraint.test
Expand Up @@ -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;
5 changes: 1 addition & 4 deletions sql/table.cc
Expand Up @@ -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<enum_vcol_info_type>(type));

switch (type) {
case VCOL_GENERATED_VIRTUAL:
Expand Down Expand Up @@ -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))
{
Expand Down

0 comments on commit 7a1b058

Please sign in to comment.