Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSE6x-0006Gg-10 for pgsql-sql@arkaria.postgresql.org; Fri, 04 Oct 2013 22:44:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VSE6w-00063w-GX for pgsql-sql@arkaria.postgresql.org; Fri, 04 Oct 2013 22:44:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSE6v-00063p-IO for pgsql-sql@postgresql.org; Fri, 04 Oct 2013 22:44:37 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSE6t-0001B8-0k for pgsql-sql@postgresql.org; Fri, 04 Oct 2013 22:44:37 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VSE6r-0007Xx-Kb for pgsql-sql@postgresql.org; Fri, 04 Oct 2013 15:44:33 -0700 Date: Fri, 4 Oct 2013 15:44:33 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1380926673606-5773428.post@n5.nabble.com> In-Reply-To: References: <1380924543966-5773424.post@n5.nabble.com> Subject: Re: Advice on defining indexes MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.8 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org JORGE MALDONADO wrote > If a table has a foreign key on 2 fields, should I also create an index > composed of such fields? Yes. If you want to truly/actually model a foreign key the system will require you to create a unique constraint/index on the "primary/one" side of the relationship. CREATE TABLE list ( lst_source, lst_date, FOREIGN KEY (lst_source, lst_date) REFERENCES source (src_id, src_date) ...; If a unique constraint (in this case I'd suggest primary key) does not exist for source(src_id, src_date) the create table with the foreign key will fail. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Advice-on-defining-indexes-tp5773423p5773428.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql