pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedforeign key is it a real key
3+ messages / 2 participants
[nested] [flat]
* foreign key is it a real key
@ 2012-02-13 15:46 John Fabiani <johnf@jfcomputer.com>
2012-02-13 15:50 ` Re: foreign key is it a real key Andreas Kretschmer <akretschmer@spamfence.net>
0 siblings, 1 reply; 3+ messages in thread
From: John Fabiani @ 2012-02-13 15:46 UTC (permalink / raw)
To: pgsql-sql
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.
Thanks in advance,
Johnf
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: foreign key is it a real key
2012-02-13 15:46 foreign key is it a real key John Fabiani <johnf@jfcomputer.com>
@ 2012-02-13 15:50 ` Andreas Kretschmer <akretschmer@spamfence.net>
2012-02-13 17:30 ` Re: foreign key is it a real key John Fabiani <johnf@jfcomputer.com>
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Kretschmer @ 2012-02-13 15:50 UTC (permalink / raw)
To: pgsql-sql
John Fabiani <johnf@jfcomputer.com> 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°
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: foreign key is it a real key
2012-02-13 15:46 foreign key is it a real key John Fabiani <johnf@jfcomputer.com>
2012-02-13 15:50 ` Re: foreign key is it a real key Andreas Kretschmer <akretschmer@spamfence.net>
@ 2012-02-13 17:30 ` John Fabiani <johnf@jfcomputer.com>
0 siblings, 0 replies; 3+ messages in thread
From: John Fabiani @ 2012-02-13 17:30 UTC (permalink / raw)
To: pgsql-sql
On Monday, February 13, 2012 04:50:47 PM Andreas Kretschmer wrote:
> John Fabiani <johnf@jfcomputer.com> 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
Thanks
Johnf
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2012-02-13 17:30 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-02-13 15:46 foreign key is it a real key John Fabiani <johnf@jfcomputer.com>
2012-02-13 15:50 ` Andreas Kretschmer <akretschmer@spamfence.net>
2012-02-13 17:30 ` John Fabiani <johnf@jfcomputer.com>
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