Re: 7.4 - FK constraint performance

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: ow <oneway_111(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: 7.4 - FK constraint performance
Date: 2004-02-12 15:37:32
Message-ID: 20040212072447.H86595@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

On Thu, 12 Feb 2004, ow wrote:

>
> --- Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> wrote:
> > Hmm, I'd wonder if maybe it's choosing a sequential scan in the second
> > case? As a random question, does increasing the statistics target on
> > Large.small_id and re-analyzing change its behavior?
>
> Ran analyze, the result is the same. Here's more info:

You also did the alter table to up the statistics target on the column,
right?

> 3) delete from Small where id = 239
> Runs for about 3 min. It does appear that table scan is used for FK
> verification. But why? Am deleting "id = 239" not "id = 1" and the query in
> (1) runs very quickly. Had suspicion that wrong id is passed during FK
> verification but FK constraint DOES work.

It doesn't plan it as id=239 but as id=$1 and then executes it with
$1=239. The plan data gets reused for other id values if it needs the
same fk action again later in the session.

I'd hoped that upping the statistics target and re-analyzing would make it
choose an index scan for the case where it doesn't know what constant is
going to be used. Hmm, what is the estimated cost difference and real
time difference on id=1 between seqscan and index scan (explain analyze
output with and without enable_seqscan=off should show you).

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2004-02-12 15:45:03 Re: Transaction aborts on syntax error.
Previous Message scott.marlowe 2004-02-12 15:37:06 Re: How can I have 2 completely seperated databases in

Browse pgsql-sql by date

  From Date Subject
Next Message ow 2004-02-12 15:53:51 Re: 7.4 - FK constraint performance
Previous Message Bruce Momjian 2004-02-12 15:10:38 Re: array_lower /array_prepend doubt