Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B640E1FC9B63 for ; Mon, 13 Feb 2012 11:51:08 -0400 (AST) Received: from mailout01.ims-firmen.de ([213.174.32.96]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RwyBB-0007MQ-Ss for pgsql-sql@postgresql.org; Mon, 13 Feb 2012 15:51:07 +0000 Received: from mailin03.ims-firmen.de ([192.168.1.112]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1RwyAy-0006ZS-N7 for pgsql-sql@postgresql.org; Mon, 13 Feb 2012 16:50:48 +0100 Received: from [87.170.193.148] (helo=a-kretschmer.de) by mailin03.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1RwyAy-0000o6-HM for pgsql-sql@postgresql.org; Mon, 13 Feb 2012 16:50:48 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1RwyAx-0006fX-SX for pgsql-sql@postgresql.org; Mon, 13 Feb 2012 16:50:47 +0100 Date: Mon, 13 Feb 2012 16:50:47 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: foreign key is it a real key Message-ID: <20120213155047.GA25335@tux> References: <5075215.HTHcEtzjPG@linux-12> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5075215.HTHcEtzjPG@linux-12> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/42 X-Sequence-Number: 36335 John Fabiani wrote: > Hi, > I have read a few articles and I'm not sure if it's me or the authors but I do > not believe my question was answered. > > If I have table that has a PK and a FK - will the planner use the FK just same > as it would use the PK? IOW's is a FK also an index used by the planner? > > I have a lagacy table that contains a FK constraint (vendor_id --> > vendor_info). I believe I need an index to improve the performance of a query > because I'm using the column as part of my join. Explain does not appear to > use it as an index (instead of a seq scan it uses a hash join). But the table > all ready has a FK key contraint on the column. Yes, for large tables you have to create a own index on your fk-column. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°