Re: FOREIGN KEYS vs PERFORMANCE

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
Cc: PFC <lists(at)peufeu(dot)com>, Michael Glaesemann <grzm(at)myrealbox(dot)com>, Rodrigo Sakai <rodrigo(dot)sakai(at)zanthus(dot)com(dot)br>, pgsql-performance(at)postgresql(dot)org
Subject: Re: FOREIGN KEYS vs PERFORMANCE
Date: 2006-04-12 15:39:51
Message-ID: 20060412153951.GH49405@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Apr 12, 2006 at 07:45:17AM -0700, Craig A. James wrote:
> All good advice, but... there are no absolutes in this world.
> Application-enforced referential integrity makes sense if (and probably
> ONLY if):
>
> 1. You have only one application that modifies the data. (Otherwise, you
> have to duplicate the rules across many applications, leading to a
> code-maintenance nightmare).

You forgot something:

1a: You know that there will never, ever, ever, ever, be any other
application that wants to talk to the database.

I know tons of people that get burned because they go with something
that's "good enough for now", and then regret that decision for years to
come.

> 2. If your application crashes and leaves a mess, it's not a catastrophe,
> and you have a good way to clean it up. For example, a bank shouldn't do
> this, but it might be OK for a computer-aided-design application, or the
> backend of a news web site.
>
> 3. You have application-specific knowledge about when you can skip
> referential integrity and thereby greatly improve performance. For
> example, you may have batch operations where large numbers of rows are
> temporarily inconsistent.
>
> If your application doesn't meet ALL of these criteria, you probably should
> use the database for referential integrity.
>
> Craig
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Craig A. James 2006-04-12 17:36:28 Re: FOREIGN KEYS vs PERFORMANCE
Previous Message Jim C. Nasby 2006-04-12 15:36:20 Re: FOREIGN KEYS vs PERFORMANCE