mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-12421 Check constraint with query crashes server and renders DB unusable
parse CHECK constraint *before* Column_definition validity checks
This commit is contained in:
@@ -140,3 +140,7 @@ create table t1 (a int, b int, check(a>0));
|
|||||||
alter table t1 drop column a;
|
alter table t1 drop column a;
|
||||||
ERROR 42S22: Unknown column 'a' in 'CHECK'
|
ERROR 42S22: Unknown column 'a' in 'CHECK'
|
||||||
drop table t1;
|
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`
|
||||||
|
@@ -86,3 +86,11 @@ create table t1 (a int, b int, check(a>0));
|
|||||||
--error ER_BAD_FIELD_ERROR
|
--error ER_BAD_FIELD_ERROR
|
||||||
alter table t1 drop column a;
|
alter table t1 drop column a;
|
||||||
drop table t1;
|
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));
|
||||||
|
@@ -6013,8 +6013,8 @@ field_list_item:
|
|||||||
;
|
;
|
||||||
|
|
||||||
column_def:
|
column_def:
|
||||||
field_spec opt_check_constraint
|
field_spec
|
||||||
{ $$= $1; $$->check_constraint= $2; }
|
{ $$= $1; }
|
||||||
| field_spec references
|
| field_spec references
|
||||||
{ $$= $1; }
|
{ $$= $1; }
|
||||||
;
|
;
|
||||||
@@ -6152,11 +6152,13 @@ field_spec:
|
|||||||
lex->init_last_field(f, $1.str, NULL);
|
lex->init_last_field(f, $1.str, NULL);
|
||||||
$<create_field>$= f;
|
$<create_field>$= f;
|
||||||
}
|
}
|
||||||
field_type_or_serial
|
field_type_or_serial opt_check_constraint
|
||||||
{
|
{
|
||||||
LEX *lex=Lex;
|
LEX *lex=Lex;
|
||||||
$$= $<create_field>2;
|
$$= $<create_field>2;
|
||||||
|
|
||||||
|
$$->check_constraint= $4;
|
||||||
|
|
||||||
if ($$->check(thd))
|
if ($$->check(thd))
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user