Many-To-Many Bridge Table Index

From: Sergei Dubov <sdubov(at)gmail(dot)com>
To: PG-General <pgsql-general(at)postgresql(dot)org>
Subject: Many-To-Many Bridge Table Index
Date: 2005-09-29 19:44:09
Message-ID: 433C4409.9090007@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi guys,

I'd really appreciate if you could clarify this to me. Let's say I have
a table named TABLE_A that is a bridge to many-to-many relationship
between TABLE_B and TABLE_C, as such here is my declaration:

CREATE TABLE table_a (
table_b_id INT4 NOT NULL
REFERENCES table_b ON DELETE CASCADE ON UPDATE CASCADE,

table_c_id INT4 NOT NULL
REFERENCES table_c ON DELETE RESTRICT ON UPDATE CASCADE,

CONSTRAINT table_a_pkey
PRIMARY KEY (table_b_id, table_c_id)
);

This will automatically create a unique index on the primary key.

Well, if I do a query later like:

select * from table_a where table_b_id=1,

will the query use an index? Will this be true when I do join on this table?

Thanks so much,

Serge

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2005-09-29 19:46:05 Re: pl/pgsql function debugging
Previous Message Shane Dawalt 2005-09-29 19:42:23 Re: 8.0.1 SRPM on RHEL v.3