← Back to team overview

maria-developers team mailing list archive

Re: [Commits] Rev 3966: MDEV-4439 ALTER TABLE .. [ADD|DROP] FOREIGN KEY IF [NOT] EXISTS does not work if constraint name is not used. in file:///home/hf/wmar/10-hf/

 

Hi, Jan!

Good point!

On Feb 02, Jan Lindström wrote:
> Hi,
> 
> In my opinion the test case is not complete, you are missing e.g.
> 
> ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS (id) REFERENCES t1(id);
> -- should fail on warning
> ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS (id) REFERENCES t1(id);

I suppose in the current implementation "IF NOT EXISTS" clause won't
help, because the FK name is generated in the engine.

Holyfoot, perhaps it'd still make sense to move the check down into the
engine?

> ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS a(id REFERENCES t1(id);
> -- should fail, there is already foreign key for id, yes it name is not b or a but anyway
> ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS b(id) REFERENCES t1(id);

Detecting identically defined foreign key constraints isn't part of this
task. This task only operates with object names.

By the way, similar tests are possible for DROP too.

Regards,
Sergei



Follow ups

References