Thread: performance of foreign key constraints

performance of foreign key constraints

From
teknokrat
Date:
I have a table that has about 20 foreign key constraints on it. I think
this is a bit excessive and am considering removing them ( they are all
related to the same table and I don't think there is much chance of any
integrity violations ). Would this improve performance or not?

thanks


Re: performance of foreign key constraints

From
Andrew Sullivan
Date:
On Thu, Aug 28, 2003 at 06:15:57PM +0100, teknokrat wrote:
> I have a table that has about 20 foreign key constraints on it. I think
> this is a bit excessive and am considering removing them ( they are all
> related to the same table and I don't think there is much chance of any
> integrity violations ). Would this improve performance or not?

Almost certainly.  But there's probably room for some middle ground
between 20 and none.

A

--
----
Andrew Sullivan                         204-4141 Yonge Street
Liberty RMS                           Toronto, Ontario Canada
<andrew@libertyrms.info>                              M2P 2A8
                                         +1 416 646 3304 x110


Re: performance of foreign key constraints

From
Stephan Szabo
Date:
On Thu, 28 Aug 2003, teknokrat wrote:

> I have a table that has about 20 foreign key constraints on it. I think
> this is a bit excessive and am considering removing them ( they are all
> related to the same table and I don't think there is much chance of any
> integrity violations ). Would this improve performance or not?

It depends on your frequency of inserts/updates to the table with the
constraint and the frequency of update/delete to the table(s) being
refered to. My guess is probably.  You may wish to leave some of the
constraints (decide which are the most important), but 20 does seem a bit
excessive in general.


Re: performance of foreign key constraints

From
teknokrat
Date:
Stephan Szabo wrote:

> On Thu, 28 Aug 2003, teknokrat wrote:
>
>
>>I have a table that has about 20 foreign key constraints on it. I think
>>this is a bit excessive and am considering removing them ( they are all
>>related to the same table and I don't think there is much chance of any
>>integrity violations ). Would this improve performance or not?
>
>
> It depends on your frequency of inserts/updates to the table with the
> constraint and the frequency of update/delete to the table(s) being
> refered to. My guess is probably.  You may wish to leave some of the
> constraints (decide which are the most important), but 20 does seem a bit
> excessive in general.
>

The references are all to the same table i.e. they are employee ids, so
leaving some and not others would make no sense. The table has no
deletes, small amount of inserts and moderate amount of updates. However
there are many selects and its their performance I am most concerned with.

thanks


Re: performance of foreign key constraints

From
Stephan Szabo
Date:
On Thu, 28 Aug 2003, teknokrat wrote:

> Stephan Szabo wrote:
>
> > On Thu, 28 Aug 2003, teknokrat wrote:
> >
> >
> >>I have a table that has about 20 foreign key constraints on it. I think
> >>this is a bit excessive and am considering removing them ( they are all
> >>related to the same table and I don't think there is much chance of any
> >>integrity violations ). Would this improve performance or not?
> >
> >
> > It depends on your frequency of inserts/updates to the table with the
> > constraint and the frequency of update/delete to the table(s) being
> > refered to. My guess is probably.  You may wish to leave some of the
> > constraints (decide which are the most important), but 20 does seem a bit
> > excessive in general.
> >
>
> The references are all to the same table i.e. they are employee ids, so
> leaving some and not others would make no sense. The table has no
> deletes, small amount of inserts and moderate amount of updates. However
> there are many selects and its their performance I am most concerned with.

The foreign keys should only really affect insert/update/delete
performance.  If you're using 7.3.4 (I think) then updates to the fk table
that don't change any of the keys should be relatively cheap.  I'd be much
more worried if you had any changes the the referenced employee table that
might change the key because that could get relatively expensive.



Re: performance of foreign key constraints

From
Rod Taylor
Date:
> The references are all to the same table i.e. they are employee ids, so
> leaving some and not others would make no sense. The table has no
> deletes, small amount of inserts and moderate amount of updates. However
> there are many selects and its their performance I am most concerned with.

Foreign keys have no impact on selects.

Although this does sound like a rather strange design to me (20+ columns
wide and they're all employee ids?)

Attachment

Re: performance of foreign key constraints

From
teknokrat
Date:
Rod Taylor wrote:
>>The references are all to the same table i.e. they are employee ids, so
>>leaving some and not others would make no sense. The table has no
>>deletes, small amount of inserts and moderate amount of updates. However
>>there are many selects and its their performance I am most concerned with.
>
>
> Foreign keys have no impact on selects.
>
> Although this does sound like a rather strange design to me (20+ columns
> wide and they're all employee ids?)

There are more than 20 fieldss. Its a report that can get updated by
different employees and we wish to keep a record of which employee
completed which section. Couldn't think of any other way to do it.