← Back to team overview

maria-developers team mailing list archive

Re: Analysis of the same name of field and name check constraints


Hi Vincentiu,
Sorry but I have seen now, after sending the mail, that example in this
mail is not relevant, please take a look in a example in PR.


On Mon, Apr 23, 2018 at 12:45 PM, Anel Husakovic <anel@xxxxxxxxxxx> wrote:

> Hi Vicentiu,
> Regarding the check constraints with *field *and *table *constraint that
> have the same name for example:
> *`create table t (a int, b check(b>0), constraint b check (b>10));`*
> when new rows are inserted and an error occurs, generated error is not
> pointing to exact constraint. For example:
> *`insert into t values (-1);`*
> ERROR 4025 (23000): CONSTRAINT `b` failed for `test`.`t`
> but this means different constraint.
> In order to solve this, here are my opinions:
> 1. approach is not to allow this scenario while creating the table,
> 2. approach is to generate different message one message for *table *constraint
> second for *field *constraint depending where error occurs- and you told
> me to go with this one.
> Out of curiosity I also tried with 1. approach problem is that in
> *sql/sql_table.cc **mysql_prepare_create_table 4221*
> *create/alter_info.check_constraint_list *is tied to table constraints.
> However there is another attribute *field_check_constraints *for
> *create_info *object but it is always *0*. It is updated in
> * sql/unireg.cc* *783*. Problem is that *mysql_prepare_create_table *is
> called first  and after that *field_check_constraints *is updated,so
> there is no mechanism to allow check in early stage for *table*-*field *check
> constraint.
> After that there is a validation according to the each constraint in
> *sql/table.cc* *verify_constraints 5232* - and this is 2. approach.
> I finished 2. approach and what I have that each test already written in
> main directory failed because of different error message for a specific
> case.
> So here is a patch for 2. approach:
> https://github.com/MariaDB/server/pull/715
> In this approach we are handling each error independently.
> Also we need to change each test regarding the ER_CONSTRAINT_FAILED where
> should be raised newly created error ER_FIELD_CONSTRAINT_FAILED.
> Also I have updated PR *IS.check_constraint *, rebased everything in one
> file
> https://github.com/MariaDB/server/pull/689/
> Best regards,
> Anel