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

How do FKs work?

From: "Marc G(dot) Fournier" <scrappy(at)hub(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: How do FKs work?
Date: 2004-10-09 18:08:51
Message-ID: 20041009145332.D54093@ganymede.hub.org (view raw or flat)
Thread:
Lists: pgsql-sql
Got a problem here, and this is a new area for me ... analyzing FKs and 
improving their performance :)

Have a table with two FKs on it ... 2 different fields in the table point 
to the same field in another table ...

When I do an 'EXPLAIN ANALYZE DELETE FROM table WHERE field = #;', it 
never comes back ... or, at lesat, takes a *very* long time ...

If I do a count(1) for that #, there are 1639 rows ...

Now, 'ON DELETE' is set to 'NO ACTION', so my *guess* is that all it does 
is a 'SELECT FROM table WHERE field = value' on the referenced table, to 
make sure it exists ...

Is this correct?   So, its effectively having to do 3278 "SELECTS" against 
the REFERENCED table? (two fields have contraints on them, 1639 rows to be 
deleted) ... ?



----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email: scrappy(at)hub(dot)org           Yahoo!: yscrappy              ICQ: 7615664

Responses

pgsql-sql by date

Next:From: Andrew WardDate: 2004-10-09 20:39:45
Subject: SQL confusion
Previous:From: Paulo NievierowskiDate: 2004-10-09 15:11:37
Subject: Re: SELECT with Function

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