pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PFC <lists@peufeu.com>
To: Campbell, Lance <lance@uiuc.edu>
To: pgsql-performance@postgresql.org
Subject: Re: Creating a foreign key
Date: Thu, 08 May 2008 22:02:47 +0200
Message-ID: <op.uaupyxsecigqcu@apollo13.peufeu.com> (raw)
In-Reply-To: <B10E6810AC2A2F4EA7550D072CDE8760CDDD46@SAB-FENWICK.sab.uiuc.edu>
References: <B10E6810AC2A2F4EA7550D072CDE8760CDDD46@SAB-FENWICK.sab.uiuc.edu>


> When you create a foreign key to a table is there an index that is
> created on the foreign key automatically?

	No, Postgres doesn't do it for you, because if you create (ref_id)  
references table.id, you will perhaps create an index on (ref_id, date)  
which would then fill the purpose (and other purposes), or perhaps your  
table will have 10 rows (but postgres doesnt' know that when you create  
it) and having an index would be useless, or your table could have many  
rows but only a few distinct referenced values, in which case again the  
index would only slow things down.
	PG does not presume to know better than yourself what you're gonna do  
with your data ;)
	UNIQUE and PRIMARY KEY do create UNIQUE INDEXes, of course.



view thread (5+ messages)

Message-ID: <op.uaupyxsecigqcu@apollo13.peufeu.com>
Permalink:  ../op.uaupyxsecigqcu@apollo13.peufeu.com/
Also on:    postgresql.org/message-id/op.uaupyxsecigqcu@apollo13.peufeu.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: lists@peufeu.com, lance@uiuc.edu
  Subject: Re: Creating a foreign key
  In-Reply-To: <op.uaupyxsecigqcu@apollo13.peufeu.com>

* 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