Re: Will PG use composite index to enforce foreign keys?

From: John Burger <john(at)mitre(dot)org>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Will PG use composite index to enforce foreign keys?
Date: 2007-12-03 18:03:54
Message-ID: 3DADA3B9-9DC8-4F8E-A921-B425980F4A23@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gregory Stark wrote:

>> I guess a generalization of my question is whether the FK-
>> checking machinery
>> simply does a SELECT against the referencing column.
>
> It does

> Actually the query is (effectively, assuming your equality
> operators are named
> "=" and the columns match in type)
>
> SELECT 1
> FROM ONLY B x
> WHERE col1=?
> AND col2=?
> ...
> FOR SHARE OF x
>
> Since it has to take a lock on the record found to ensure it
> doesn't disappear
> before your transaction finishes.

Awesome, this tells me a lot! So I can use EXPLAIN ANALYZE and a
query like this to reason about what indexes I might need on my
foreign key references. Thanks!

- John D. Burger
MITRE

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josh Harrison 2007-12-03 18:07:18 Re: initdb - encoding question
Previous Message brian 2007-12-03 18:01:14 Re: initdb - encoding question