pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Roy Brokvam <roy.brokvam@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Meaning of pg_constraint.conindid for foreign keys
Date: Thu, 27 Apr 2017 11:57:45 +0100
Message-ID: <871sseuo4v.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CADhin7Xj7FFp3N+d_J=4ya8iqo+hnoyX23vYEA35guMDDuGzbg@mail.gmail.com>
References: <CADhin7Xj7FFp3N+d_J=4ya8iqo+hnoyX23vYEA35guMDDuGzbg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "Roy" == Roy Brokvam <roy.brokvam@gmail.com> writes:

 Roy> After investigating further, saw that conindid contained the oid
 Roy> of the referenced table's primary key, not the oid of the index
 Roy> "implementing" the foreign key.

FKs aren't implemented using an index on the referencing table, only on
the referenced table.

i.e. given:

CREATE TABLE foo (id integer PRIMARY KEY);
CREATE TABLE bar (foo_id integer REFERENCES foo);

the constraint depends on the existence of the index foo_pkey (and it's
this one which is recorded in the system catalogs), but there is no
index at all on bar; even if you created an index on bar(foo_id), it
would not be associated in any way with the FK constraint (though it
would improve the performance of updates/deletes in foo, because the
query issued by the constraint check would likely use it).

So you're looking in the wrong place.

-- 
Andrew (irc:RhodiumToad)


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <871sseuo4v.fsf@news-spur.riddles.org.uk>
Permalink:  ../871sseuo4v.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/871sseuo4v.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, roy.brokvam@gmail.com
  Subject: Re: Meaning of pg_constraint.conindid for foreign keys
  In-Reply-To: <871sseuo4v.fsf@news-spur.riddles.org.uk>
  References: <CADhin7Xj7FFp3N+d_J=4ya8iqo+hnoyX23vYEA35guMDDuGzbg@mail.gmail.com> <871sseuo4v.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox