Re: 7.4 - FK constraint performance - Mailing list pgsql-sql

From ow
Subject Re: 7.4 - FK constraint performance
Date
Msg-id 20040212140516.65859.qmail@web60807.mail.yahoo.com
Whole thread Raw
In response to Re: 7.4 - FK constraint performance  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Responses Re: 7.4 - FK constraint performance  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-sql
--- Stephan Szabo <sszabo@megazone.bigpanda.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:

1) There's 1 row in "Large" for "small_id" = 239 
SELECT 1 FROM ONLY "my"."Large" x WHERE "small_id" = 239 FOR UPDATE OF x

Quick query. Explain shows index scan.

2) There are many rows in "Large" for "small_id" = 1
SELECT 1 FROM ONLY "my"."Large" x WHERE "small_id" = 1 FOR UPDATE OF x

Runs for about 3 min. Explain shows table scan.

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.

4) Domain types used in the example above
my.dint = int
my.dlong = int8
my.dvalue =  varchar(15)

Thanks




__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html


pgsql-sql by date:

Previous
From: Tomasz Myrta
Date:
Subject: Re: How to avoid nulls while writing string for dynamic query
Next
From: Bruce Momjian
Date:
Subject: Re: array_lower /array_prepend doubt