Skip site navigation (1) Skip section navigation (2)

Re: FK check will use index on referring table?

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: "John D(dot) Burger" <john(at)mitre(dot)org>
Cc: General PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: FK check will use index on referring table?
Date: 2008-07-25 01:06:26
Message-ID: 20080725010626.GC16005@tamriel.snowman.net (view raw or flat)
Thread:
Lists: pgsql-general
* John D. Burger (john(at)mitre(dot)org) wrote:
> My understanding is that PG will use an index on the referring side of a 
> foreign key for FK checks.  How can I tell whether it's doing that?  

It should, when it makes sense, yes.  Having the actual schema
definitions would help in debugging this, of course.

> EXPLAIN ANALYZE just shows something like this:
>
> => explain analyze delete from segments where segmentid = 24305259;

What does:

explain analyze
delete from tokenizedSegments
where segmentId = 24305259;

look like?

If more than a few percent of the tokenizedSegments table has a
segmentId of 24305259 then PG may rightly be scanning the whole table
sequantially because going through it randomly with an index would be
slower.  There's a few options which can tune those parameters in the
planner, of course, but you might consider doing a test
'set enable_seqscan = false;' first, if it's indeed doing one, to see
what the difference really is.

	Thanks,

		Stephen

In response to

Responses

pgsql-general by date

Next:From: Tom LaneDate: 2008-07-25 03:15:58
Subject: Re: FK check will use index on referring table?
Previous:From: Klint GoreDate: 2008-07-25 00:26:26
Subject: Re: [PERL DBI] Insertiing data across multiple tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group