Skip to content

Commit

Permalink
MDEV-12421 Check constraint with query crashes server and renders DB …
Browse files Browse the repository at this point in the history
…unusable

parse CHECK constraint *before* Column_definition validity checks
  • Loading branch information
vuvova committed Apr 1, 2017
1 parent 6315426 commit 22d8bb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions mysql-test/r/check_constraint.result
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ 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;
create table t1 (a int check (@b in (select user from mysql.user)));
ERROR HY000: Function or expression 'select ...' cannot be used in the CHECK clause of `a`
create table t1 (a int check (a > @b));
ERROR HY000: Function or expression '@b' cannot be used in the CHECK clause of `a`
8 changes: 8 additions & 0 deletions mysql-test/t/check_constraint.test
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ create table t1 (a int, b int, check(a>0));
--error ER_BAD_FIELD_ERROR
alter table t1 drop column a;
drop table t1;

#
# MDEV-12421 Check constraint with query crashes server and renders DB unusable
#
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
create table t1 (a int check (@b in (select user from mysql.user)));
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
create table t1 (a int check (a > @b));
8 changes: 5 additions & 3 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -6013,8 +6013,8 @@ field_list_item:
;

column_def:
field_spec opt_check_constraint
{ $$= $1; $$->check_constraint= $2; }
field_spec
{ $$= $1; }
| field_spec references
{ $$= $1; }
;
Expand Down Expand Up @@ -6152,11 +6152,13 @@ field_spec:
lex->init_last_field(f, $1.str, NULL);
$<create_field>$= f;
}
field_type_or_serial
field_type_or_serial opt_check_constraint
{
LEX *lex=Lex;
$$= $<create_field>2;

$$->check_constraint= $4;

if ($$->check(thd))
MYSQL_YYABORT;

Expand Down

0 comments on commit 22d8bb2

Please sign in to comment.