Re: Over-indexing m2m table for FKs?

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: sfpug(at)postgresql(dot)org
Subject: Re: Over-indexing m2m table for FKs?
Date: 2013-05-18 20:39:07
Message-ID: 5197E6EB.2070205@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: sfpug


> table sidea (a_id)
> table sideb (b_id)
> table a_to_b (a_id references sidea on delete cascade, b_id references
> sideb on delete cascade)
>
> a_to_b is unique, so: create unique index idx ON a_to_b (a_id, b_id)

I'd add a 2nd index: create index on a_to_b(b_id).

This should be sufficient for most uses. Certainly an additional index
on only (a_id) would be redundant.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com

In response to

Responses

Browse sfpug by date

  From Date Subject
Next Message Sam Solomon 2013-05-20 17:06:17 Re: Over-indexing m2m table for FKs?
Previous Message Brian Ghidinelli 2013-05-18 20:29:34 Over-indexing m2m table for FKs?