dbTalk Databases Forums  

Problems when adding foreign keys

comp.databases.informix comp.databases.informix


Discuss Problems when adding foreign keys in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ulf
 
Posts: n/a

Default Problems when adding foreign keys - 08-02-2011 , 01:56 AM






Hi !

We are using version 11.50.FC6W2 on HP-UX 11.31

I have on several occasions run into a problem when adding foreign
keys, the problem is the following.

I have a table A with a primary key. I now add a table B that has a
foreign key constraint to the primary key on table A.

Problem 1. If it is not possible to lock table A in exclusive mode I
can't add the foreign key. Why is there a need for an exclusive lock
on table A in this situation ?

Problem 2. If I succed to add the foreign key I get -710 errors when
trying to update table A.Why the -710 error on table A ?
The solution I have found is to do an update statistics on table A. Is
there other ways around the problem ?


The behavior might have changed in later versions.

TIA

Ulf

Reply With Quote
  #2  
Old   
Keith Simmons
 
Posts: n/a

Default Re: Problems when adding foreign keys - 08-02-2011 , 02:39 AM






Ulf

Any change of the table structure requires an exclusive lock and
adding a constraint (such as a foreign key) is such a change.
-710 simply indicates the structrue of the table has changed.
by adding a foreign key !!, since the last time that process
accessed the table. If you had restarted the process, so that
it connected to the new 'version' of the table , you would not
have seen the error. Also it should not appear on any new
connections.

Keith

On 2 August 2011 07:56, Ulf <ulf.akerberg (AT) gmail (DOT) com> wrote:
Quote:
Hi !

We are using version 11.50.FC6W2 on HP-UX 11.31

I have on several occasions run into a problem when adding foreign
keys, the problem is the following.

I have a table A with a primary key. I now add a table B that has a
foreign key constraint to the primary key on table A.

Problem 1. If it is not possible to lock table A in exclusive mode I
can't add the foreign key. Why is there a need for an exclusive lock
on table A in this situation ?

Problem 2. If I succed to add the foreign key I get -710 errors when
trying to update table A.Why the -710 error on table A ?
The solution I have found is to do an update statistics on table A. Is
there other ways around the problem ?


The behavior might have changed in later versions.

TIA

Ulf

_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
  #3  
Old   
Alexandre Marini
 
Posts: n/a

Default Re: Problems when adding foreign keys - 08-02-2011 , 06:45 AM



Hello.
You might also check if yours AUTO_REPREPARE onconfig var is turned on,
since it reduces lots of 710 errors that previously versions generated.

Regards.

Em 02/08/2011 03:39, Keith Simmons escreveu:
Quote:
Ulf

Any change of the table structure requires an exclusive lock and
adding a constraint (such as a foreign key) is such a change.
-710 simply indicates the structrue of the table has changed.
by adding a foreign key !!, since the last time that process
accessed the table. If you had restarted the process, so that
it connected to the new 'version' of the table , you would not
have seen the error. Also it should not appear on any new
connections.

Keith

On 2 August 2011 07:56, Ulf<ulf.akerberg (AT) gmail (DOT) com> wrote:
Hi !

We are using version 11.50.FC6W2 on HP-UX 11.31

I have on several occasions run into a problem when adding foreign
keys, the problem is the following.

I have a table A with a primary key. I now add a table B that has a
foreign key constraint to the primary key on table A.

Problem 1. If it is not possible to lock table A in exclusive mode I
can't add the foreign key. Why is there a need for an exclusive lock
on table A in this situation ?

Problem 2. If I succed to add the foreign key I get -710 errors when
trying to update table A.Why the -710 error on table A ?
The solution I have found is to do an update statistics on table A. Is
there other ways around the problem ?


The behavior might have changed in later versions.

TIA

Ulf

_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list


--

Alexandre Marini

Tecnologia da Informação - DBA

msn: alexandre_marini (AT) hotmail (DOT) com

SEFAZ-MS / SGI-UGSR / Sistemas IBM-Informix

<Cert-Info-Mgmt_color.jpg>

IBM Certified System Administrator - Informix Dynamic Server V10 / V11 /
V11.70

IBM Information Management Informix Technical Professional v3

Reply With Quote
  #4  
Old   
Art Kagel
 
Posts: n/a

Default Re: Problems when adding foreign keys - 08-02-2011 , 09:25 AM



Ulf:

See my responses below:

Art

Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/

Disclaimer: Please keep in mind that my own opinions are my own opinions and
do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
organization with which I am associated either explicitly, implicitly, or by
inference. Neither do those opinions reflect those of other individuals
affiliated with any entity with which I am affiliated nor those of the
entities themselves.



On Tue, Aug 2, 2011 at 2:56 AM, Ulf <ulf.akerberg (AT) gmail (DOT) com> wrote:

Quote:
Hi !

We are using version 11.50.FC6W2 on HP-UX 11.31

I have on several occasions run into a problem when adding foreign
keys, the problem is the following.

I have a table A with a primary key. I now add a table B that has a
foreign key constraint to the primary key on table A.

Problem 1. If it is not possible to lock table A in exclusive mode I
can't add the foreign key. Why is there a need for an exclusive lock
on table A in this situation ?

This is because Informix wants to validate all of the foreign keys in the
independent table (so table A) and does not want to have to deal with the
keys changing (specifically being deleted after having been verified) during
the check.


Quote:
Problem 2. If I succed to add the foreign key I get -710 errors when
trying to update table A.Why the -710 error on table A ?
The solution I have found is to do an update statistics on table A. Is
there other ways around the problem ?

This is because you are updating using prepared statements that were
prepared before the foreign key constraint on table B existed. Since the
update MAY change columns in table A that are foreign keys in table B now
the query plan that was prepared is now invalid so the -710 error is
returned. The fix, as Alexandre pointed out, is to enable AUTO_REPREPARE in
your ONCONFIG file and bounce the server. This will cause the engine to
automatically reprepare any query plan that has been invalidated by
structural changes in the database schema such as the one you are
experiencing. With AUTO_REPREPARE enabled the number of -710 that are still
returned is very small.


Quote:

The behavior might have changed in later versions.

TIA

Ulf

_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.